C# Azure SQL上的Hangfire

C# Azure SQL上的Hangfire,c#,sql-server,azure,hangfire,C#,Sql Server,Azure,Hangfire,我刚刚发布了一个使用Azure SQL的Azure网站 然而,我得到了错误 An existing connection was forcibly closed by the remote host 到达网站时,通过与Hangfire相关的回调: [Win32Exception (0x80004005): An existing connection was forcibly closed by the remote host] [SqlException (0x80131904): A t

我刚刚发布了一个使用Azure SQL的Azure网站

然而,我得到了错误

An existing connection was forcibly closed by the remote host
到达网站时,通过与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

有什么想法吗?

我也有同样的问题。如果您像我一样从Azure Portal数据库设置页面复制了连接字符串,请尝试删除
Pooling=False。这为我解决了这个问题


抱歉,我无法很好地解释为什么这会导致Hangfire失败。但通常情况下,您还是希望启用连接池。

您经常遇到这些错误吗?如果没有,请现在检查,这是web应用程序的初始部署。它就是不起作用,我使用/hangfire URL时出现此错误。我也遇到了同样的问题。您是否可以与SQL azure db分享您使用hang fire的总体经验?您是否必须增加默认轮询间隔或使用您自己的重试或容错逻辑?很抱歉回答得太晚。我只是在尝试将一个现有的应用程序迁移到Azure Web应用程序,所以我不能说我对使用Azure SQL的Hangfire有过很多经验,除非它能按预期工作。我们只在后台发送电子邮件通知,所以对容错性没有太多要求。至于轮询间隔,我不必更改默认值。