【发布时间】:2011-10-05 12:27:34
【问题描述】:
我收到此错误:
超时。在操作完成之前超时时间已过或服务器没有响应。
我知道已经有指南可以帮助解决这个问题,但它们对我不起作用。我缺少什么或者我应该在我的 C# 程序中将代码添加到这些 SQL 语句的什么位置:
String sql = project1.Properties.Resources.myQueryData;
SqlDataAdapter sqlClearQuestDefects = new SqlDataAdapter(sql,
"Data Source=ab;Initial Catalog=ac;User ID=ad; Password =aa");
DataSet lPlanViewData = new DataSet();
sqlClearQuestDefects.Fill(lPlanViewData, "PlanViewData");
我在这一行收到超时错误:
SqlDataAdapter sqlClearQuestDefects = new SqlDataAdapter(sql,
"Data Source=ab;Initial Catalog=ac;User ID=ad; Password =aa");
【问题讨论】:
-
这听起来像是连接超时,这表明您无法连接到数据库。
-
嗯,我大多数时候都正确连接到数据库,只是偶尔会收到此错误。
-
那很正常。如果它超时一次,然后当你再次执行它时,你的第一个请求就会在 TCP/IP 网络的狂野边界中丢失。我会简单地将创建 SqlDataAdapter 的代码包装在一个 try-catch 中,在向用户显示错误之前循环几次重试。
-
请在适配器命令对象属性中设置连接超时属性。默认为 60 秒。