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

相关问题