SQL Exception when processing enqueued job

Hi all,

First thanks for this great open souce project. I’m pretty recent to it, and I’ve set it up in a WindowsService. I’m using v1.3.3. along with AutoFac. Everything goes smoothly, but when an enqueued job is being processed I always get a SQL exception. The exception is above:

2015-01-29 15:25:01,004 [Worker #1] WARN Hangfire.AutomaticRetryAttribute Failed to process the job ‘2’: an exception occurred. Retry attempt 1 of 10 will be performed in 00:00:41.
System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) —> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Compile(Expression query)
at System.Data.Linq.CompiledQuery.ExecuteQuery(DataContext context, Object args)
at System.Data.Linq.CompiledQuery.Invoke[TArg0,TResult](TArg0 arg0)

It continuously stays to try processing this job and throwing this exception. The server is loaded and establishes a correct connection when initializing. Any ideas?
Thank you.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

I think this is the best answer possible :smile: Please check it is configured to allow remote connections, it is disable by default. There are a lot of topics in the internet.

Hi odinserj. It’s a great anwser, but the problem is that the server is correctly initialized and a connection is established there, correct?

2015-01-29 16:01:07,800 [4] INFO StapLogger WieWasWie.MediaHandlerService Initialize OnStart…
2015-01-29 16:01:07,925 [4] INFO Hangfire.SqlServer.SqlServerStorage Start installing Hangfire SQL objects…
2015-01-29 16:01:08,113 [4] INFO Hangfire.SqlServer.SqlServerStorage Hangfire SQL objects installed.
2015-01-29 16:01:08,144 [4] DEBUG Hangfire.Server.AutomaticRetryServerComponentWrapper Starting a new thread for server component ‘Server Bootstrapper’…
2015-01-29 16:01:08,144 [4] INFO StapLogger WieWasWie.MediaHandlerApplication initialized…
2015-01-29 16:01:08,144 [4] INFO StapLogger WieWasWie.MediaHandlerService Start OnStart…
2015-01-29 16:01:08,144 [4] INFO StapLogger HotFolderApplication starting.
2015-01-29 16:01:08,160 [Server Bootstrapper] DEBUG Hangfire.Server.AutomaticRetryServerComponentWrapper Starting server component ‘Server Bootstrapper’…
2015-01-29 16:01:08,160 [4] INFO Hangfire.BackgroundJobServer Starting Hangfire Server…
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Using job storage: ‘SQL Server: xxx’.
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Using the following options for SQL Server job storage:
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Queue poll interval: 00:00:15.
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Invisibility timeout: 00:30:00.
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Using the following options for Hangfire Server:
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Worker count: 1.
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Listening queues: ‘default’.
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Shutdown timeout: 00:00:15.
2015-01-29 16:01:08,175 [4] INFO Hangfire.BackgroundJobServer Schedule polling interval: 00:00:15.

Having a hard time to pull this one off. :\

Then it is very strange. Can you show me the beginning of exception stack trace you’ve posted initially that is before the following line?

at System.Data.Linq.CompiledQuery.Invoke[TArg0,TResult](TArg0 arg0)

Please also show me the configuration you are using for SqlServerStorage, including the connection string (without passwords :smile:).

at WWW.Core.Models.Collections.CollectionRepository.GetAllCollectionsWithAHotFolder()
at WWW.MediaHandlerService.LocalScanWorkManager.PrepareLocalWork(String baseFolder, DateTime currentDate)
at WWW.MediaHandlerService.MediaHandlerApplication.ScheduleScansToProcess()
ClientConnectionId:00000000-0000-0000-0000-000000000000

And the configuration for SqlServerStorage is:

var storage = new SqlServerStorage(ConfigurationManager.ConnectionStrings[“WWWHangFireConnection”].ConnectionString);
var options = new BackgroundJobServerOptions { WorkerCount = _serviceSettings.MaxThreads };
_server = new BackgroundJobServer(options, storage);
JobStorage.Current = storage;
_logger.Info(“WWW.MediaHandlerApplication initialized…”);

Thanks in advance odinserj

This issue has nothing to do with HangFire itself, it’s an application issue on some hardcoded connection in other layer. Sorry for my late reply.