c# Task Connection Timeout Expired.

项目中有一些Task,从某个时段起开始报以下异常。具体如下:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=1064; handshake=0; ---> System.ComponentModel.Win32Exception: The wait operation timed out ---

从异常信息看,是在于sql进行连接时出现超时,具体的猜测为:握手协议失败。

不知道有无朋友遇到过此问题。

阅读 4.5k
2 个回答

很明显是数据库都没连接上吧

看看EF是怎么写的咯,代码也没一行,瞎猜是不对的。

和Task没啥关系,就是你的异步操作里连接数据库超时。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进