vb.net SQL 查询超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15097889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:32:31  来源:igfitidea点击:

SQL Query TimeOut

c#sqlvb.netsql-server-2005

提问by Shmewnix

I have a vb.net program that runs a stored function and fills a dataset. However, due to the amount of information pulled, sometimes it times out on certain databases.

我有一个运行存储函数并填充数据集的 vb.net 程序。但是,由于提取的信息量很大,有时会在某些数据库上超时。

How can I increase the timeout of the query so as not to get hit with a timeout?

如何增加查询的超时时间以免被超时击中?

In my form button I have the following code that is NOT working (it still times out and the program errors)

在我的表单按钮中,我有以下代码不起作用(它仍然超时并且程序错误)

Me.1TableAdapter.Connection.ConnectionString = "Data Source=10.0.1.1;Initial Catalog=Database;Persist Security Info=True;User ID=USER;Password=PASSWORD; Connection Timeout = 120"

Me.1TableAdapter.Fill(Me.Dataset.1, TodayDt, TodayEnd)

Me.2TableAdapter.Fill(Me.Dataset.1, TodayDt, TodayEnd)

I get the error message:

我收到错误消息:

System.Data.SQLClient.SQLException: Timeout expired. The timeout period elapsed piror to the completion of the operation or the server is not responding.

System.Data.SQLClient.SQLException:超时已过期。操作完成前超时时间已过或服务器未响应。

回答by Eli Gassert

A connection has a timeout, but so does the command running against the connection. That timeout is for how long to wait just trying to establish the connection. See http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx

连接有超时,但针对连接运行的命令也有超时。该超时是等待多长时间尝试建立连接。请参阅http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx

So assuming you're using a SqlCommandthen set the CommandTimeoutproperty of the command.

因此,假设您正在使用SqlCommand然后设置CommandTimeout命令的属性。

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx