2

將Azure與SQL Server結合使用。在30%的隱式調用SimpleRoleProvider的情況下,我們得到一個錯誤:命名管道提供程序,錯誤:40 - 無法打開與SQL Server的連接。錯誤頻繁發生但不可重現。它看起來像一個超時..Azure和SQL Server:命名管道提供程序,錯誤:40 - 無法打開與SQL Server的連接

[Authorize(Roles = "Administrator")] 
public class AdminController : Controller 
{ 
    ... 
} 

堆棧跟蹤看起來像:

[Win32Exception (0x80004005): Access is denied] 

[SQLEXCEPTION(0x80131904):在與SQL Server建立連接時出現與網絡相關的或特定於實例的錯誤。服務器未找到或無法訪問。驗證實例名稱是否正確,並將SQL Server配置爲允許遠程連接。 (提供程序:命名管道提供程序,錯誤:40 - 無法打開與SQL Server的連接)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException異常,布爾breakConnection,操作1 wrapCloseInAction) +5296071 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5308555 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +889 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +434 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +225 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +37 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) +558 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) +67 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1052 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource 1重試,DbConnectionOptions userOptions,DbConnectionInternal &連接) 78 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(的DbConnection owningConnection,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +167 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1重試,DbConnectionOptions USEROPTIONS)143 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1重試)83 System.Data.SqlClient的.SqlConnection.Open()+86 System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext上下文,Boolean revertImpersonate)+88 System.Web.DataAccess.SqlConnectionHelper.GetConnectio (字符串用戶名)+240 System.Web.Security.RolePrincipal.IsInRole(String,String) (String role)+9461104

我們在自己的服務器上沒有這個問題。這是一個配置問題?我們正在使用免費的Azure版本。

---加成---

壞事是,MVC框架「處理」的要求,在給定的(角色 管理)的例子。框架的使用是添加一個抽象層來方便地處理「域請求」。那麼在這種情況下該怎麼辦?

在此先感謝您的幫助!

+0

奇怪,但我們感覺使用IExplorer(與Chrome比較)發生錯誤的頻率更高。 – Gerard

+0

我不認爲這是瀏覽器相關的問題。你從哪裏連接到數據庫?你的網絡服務器是否爲前提? – QFDev

+0

該數據庫是一個Azure數據庫。是的,你是對的,它不能成爲瀏覽器的問題。儘管如此,統計學上,Chrome的效果更好(!?!?) – Gerard

回答

2

我假設Azure和SQL Server的意思是SAAS Azure SQL Database(名稱變化比我能跟蹤的更快),而不是IAAS SQL Server on Windows Azure。首先需要確定您的應用程序是否受到限制,請參閱Connection Constraints,並將此文章寫爲好,請參閱:Causes of Connection Termination。如果您的應用程序受到限制,那麼您需要重新訪問您的設計並解決您被限制的具體原因。

+0

感謝您的幫助。我們將本地數據庫部署到Sql Azure,猜測這使它成爲Windows Azure上的SQL Server。由於超時,大部分會話都會受到限制。壞事是MVC框架在給定的例子中「處理」了請求。框架的使用是添加一個抽象層來方便地處理「域請求」。那麼在這種情況下該怎麼辦? – Gerard

+0

有沒有這樣的事情,'由於超時扼殺'。節流意味着您的訂閱的一個非常具體的狀態,不只是'錯誤'的另一個名稱。請**閱讀仔細鏈接的文章**,並按照該處的建議。 –

1

在SQL Azure上預期它。它應該在大約0.5%的時間發生,而不是30%。

Here's a previous question that addressed this topic

Connection failures in SQL Azure are common. This is because your application will create a connection pool but while your side thinks these connections are over, Azure could terminate them at their end and you will never know about it.

你應該實現的情況下,您的代碼重試邏輯會出現這些超時之一。微軟已經有這樣一個庫了:Transient Fault Handling Application Block

相關問題