简体   繁体   English

“信号量超时期限已过期”SQL Azure

[英]“The semaphore timeout period has expired” SQL Azure

I am running a .Net MVC Azure Web Site with a SQL Azure database accessed using Entity Framework 6. Intermittently (1 in a thousand or so requests), I get the error "System.ComponentModel.Win32Exception: The semaphore timeout period has expired" 我正在运行一个带有使用Entity Framework 6访问的SQL Azure数据库的.Net MVC Azure网站。间歇性地(大约一千个请求中的一个),我收到错误“System.ComponentModel.Win32Exception:信号量超时期限已过期”

System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. System.Data.SqlClient.SqlException:从服务器接收结果时发生传输级错误。 (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.) ---> System.ComponentModel.Win32Exception: The semaphore timeout period has expired (提供程序:TCP提供程序,错误:0 - 信号量超时期限已过期。)---> System.ComponentModel.Win32Exception:信号量超时期限已过期

There seems to be no reason for it and requests before and after the error and their interactions with SQL Azure are fine. 似乎没有理由在错误之前和之后以及它们与SQL Azure的交互都很好。 Is there any way to handle or resolve this. 有没有办法处理或解决这个问题。

Azure SQL is very different than on premise SQL. Azure SQL与内部SQL非常不同。 When an Azure SQL Server gets overloaded or goes down, it will disconnect a number of connections and when you reconnect you will get sent to another SQL Server. 当Azure SQL Server过载或关闭时,它将断开许多连接,当您重新连接时,您将被发送到另一个SQL Server。

However with TCP connections you don't know if the other end has terminated the connection unless you actually send information down it, which is why this error occurs. 但是,对于TCP连接,您不知道另一端是否已终止连接,除非您实际向下发送信息,这就是发生此错误的原因。

Once your code know the connection is terminated, it establishes a new connection on the next query, which will work just fine. 一旦你的代码知道连接被终止,它就会在下一个查询上建立一个新的连接,这将很好地工作。

With Entity Framework 6 you can now deal with Transient Fault Handling with SQL Azure using Entity Framework 使用Entity Framework 6,您现在可以使用Entity Framework处理SQL Azure的瞬态故障处理

In your DBConfiguration class you need to set your SetExecutionStrategy and configure it. 在DBConfiguration类中,您需要设置SetExecutionStrategy并对其进行配置。 Just create a new class in your project and inherit from DbConfiguration. 只需在项目中创建一个新类,并从DbConfiguration继承。

public class MyConfiguration : DbConfiguration 
{ 
    public MyConfiguration() 
    { 
        SetExecutionStrategy( 
            "System.Data.SqlClient", 
            () => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30))); 
    } 
}

Full details at Connection Resiliency / Retry Logic (EF6 onwards) 连接弹性/重试逻辑的全部细节(EF6以上)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 信号量超时期限已在Azure中过期 - The semaphore timeout period has expired in Azure 超时已过。 在 Azure sql 上的操作完成之前超时时间已过 - Timeout expired. The timeout period elapsed prior to completion of the operation on Azure sql 在sis中执行软件包会导致超时过期。 操作完成之前经过的超时时间或服务器未响应 - Execute package in ssis causes Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding SQL 错误 周转时间已过 - SQL Error The turnaround time has expired 超时时间已到。 在操作或服务器完成之前经过了超时时间。 等待操作超时-奇怪的行为 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server. The wait operation timed out - strange behavoiur 我想让一个SQL查询有超时 - I want to make an sql query has timeout 使用SQL Server在Windows Azure上运行的MVC是否没有活动超时延迟? - Is there a no activity timeout delay with MVC running on Windows Azure with the SQL Server? 连接超时到期同时存在多个请求时 - Connection Timeout Expired When there are many requests simultaneously MVC网站闲置一段时间后超时 - Timeout MVC website after period of inactivity 实体异常:底层提供者无法打开,超时已过期 - Entity Exception : the underlying provider failed to open with Timeout expired
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM