[英]“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以上)
There is a know issue where this happens during a VIP swap, and the EF6 retry strategy does not help in this scenario. 在VIP交换期间发生这种情况存在已知问题,并且EF6重试策略在此方案中没有帮助。
https://social.msdn.microsoft.com/Forums/azure/en-US/5e195f94-d4d2-4c2d-8a4e-7d66b4761510/vip-swap-and-the-semaphore-timeout-period-has-expired-errors?forum=ssdsgetstarted&prof=required https://social.msdn.microsoft.com/Forums/azure/en-US/5e195f94-d4d2-4c2d-8a4e-7d66b4761510/vip-swap-and-the-semaphore-timeout-period-has-expired-errors?论坛= ssdsgetstarted&教授为必填
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.