基于复杂查询填充临时表时如何设置超时?
以下情况如何设置命令超时时间?只是为了澄清一下,我已经在连接字符串中设置了连接超时,但我还需要设置命令超时,因为我希望查询能够在需要时运行 5 分钟,但它会在不到 1 分钟的时间内超时。几分钟。
String reportQuery = @" complicated query returning many rows ";
SqlConnection ReportConnect = new SqlConnection(ConnectionString);
ReportConnect.Open();
DataSet tempDataset = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(reportQuery, ReportConnect);
da.Fill(tempDataset);
How do I set the command timeout in the following situation? Just to clarify, I have already set the connection timeout in the Connection String, but I also need to set the command timeout because I want the query to be able to run 5 minutes if it needs to, but it times out in less than a few minutes.
String reportQuery = @" complicated query returning many rows ";
SqlConnection ReportConnect = new SqlConnection(ConnectionString);
ReportConnect.Open();
DataSet tempDataset = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(reportQuery, ReportConnect);
da.Fill(tempDataset);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个
SqlCommand
,并在命令上设置CommandTimeout
属性,然后将其传递给数据适配器的构造函数。像这样的事情:You can create a
SqlCommand
set theCommandTimeout
property on the command and then pass that to the constructor of the data adapter. Somthing like this: