“System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 – 信号灯超时时间已到)”的解决方案

“System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - 信号灯超时时间已到)”的解决方案

文章目录

描述

最近在使用 EFCore 连接 SqlServer 数据库时,遇到如下的报错信息:

an exception has been raised that is likely due to a transient failure.
 Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseSqlServer' call.
  ---> System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - 信号灯超时时间已到)
  ---> System.ComponentModel.Win32Exception: 信号灯超时时间已到

解决

在连接字符串中加入 Packet Size=512 就可以了,代码如下:

Server=localhost;
port=3306;
Database=yourDatabase;
Uid=yourUserId;
Pwd=yourPassword;
Allow User Variables=True;
sslMode=None;
Packet Size=512;

本文由 .Net中文网 原创发布,欢迎大家踊跃转载。

转载请注明本文地址:https://www.byteflying.com/archives/3602

发表评论

登录后才能评论