Hangfire on Azure SQL
Asked Answered
S

1

5

I just published an Azure Website using an Azure SQL.

However, I get the error

An existing connection was forcibly closed by the remote host

when reaching the website, with the callback related to Hangfire:

[Win32Exception (0x80004005): An existing connection was forcibly closed by the remote host]

[SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)]
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +830
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +329
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +507
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217
   System.Data.SqlClient.SqlConnection.Open() +96
   Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection() +49
   Hangfire.SqlServer.SqlServerStorage.UseConnection(Func`2 func) +41
   Hangfire.SqlServer.SqlServerStorage.UseTransaction(Func`2 func, Nullable`1 isolationLevel) +84
   Hangfire.SqlServer.SqlServerStorage.UseTransaction(Action`1 action) +73
   Hangfire.SqlServer.SqlServerWriteOnlyTransaction.Commit() +47
   Hangfire.RecurringJobManager.AddOrUpdate(String recurringJobId, Job job, String cronExpression, TimeZoneInfo timeZone, String queue) +277

Any idea?

Sumbawa answered 15/5, 2016 at 18:47 Comment(3)
do you get these errors often? If no, check this linkAbsenteeism
Sadly now, it's the initial deploy of the web apps. It just don't work, and I get this error, using /hangfire urlSumbawa
I'm having the same issue.Portend
P
8

I had exactly the same problem. If you, like me, copied the connection string from Azure Portal database settings page, try removing Pooling=False;. This fixed the issue for me.

Sorry, I don't have a good explanation of why this was causing Hangfire to fail. But normally, you would want to have connection pooling enabled anyway.

Peculiarize answered 22/5, 2016 at 15:32 Comment(3)
Can you share your overall experience using hang fire with SQL azure db?Angstrom
Did you have to increase the default polling interval or roll your own kind of retry or fault tolerance logic?Angstrom
Sorry for late answer. I was just experimenting with moving one of the existing applications to Azure Web Apps, so I cannot say that I have had a lot of experience using Hangfire with Azure SQL other than it worked as expected. And we only use it to send email notifications in background, so there's not a lot of requirements for fault tolerance. As for polling interval, I did not have to change the default one.Peculiarize

© 2022 - 2024 — McMap. All rights reserved.