如何将连接超时设置为无穷大(直到命令完成) [英] how to set connection timeout to infinity(till command completes)

查看:149
本文介绍了如何将连接超时设置为无穷大(直到命令完成)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个在Windows应用程序中使用的连接字符串,我需要设置连接超时属性。它应该是infinte或直到命令完成。

这里是连接字符串的代码...



i have written a connection string to be used in a Windows appliation, to which i need to set connection timeout property. it should be infinte or till the command completes.
here is the code of connection string...

string strCon = "Database=inventory;UserID=root;Password=root;server=localhost;Connection Timeout=900";//60 second * 15 minutes





但不起作用。给出例外......服务器超时。

plz帮助我。



but its not working. Gives exception ... "Server timed out."
plz help me out.

推荐答案

最常被接受的方法是通过

SqlCommand对象的CommandTimeout属性。

将其设置为0表示无限超时。

有关详细信息,请单击此处。
Most accepted method of doing this is through the
CommandTimeout property of the SqlCommand object.
Set it to 0 for an infinite timeout.
For More Information click here.


将连接超时置于0 。值为0表示没有限制(执行命令的尝试将无限期地等待)。

但是不要在连接字符串中设置连接超时。因为尝试连接无限期等待。所以你可以在你的命令中使用像SqlCommand.CommandTimeout = 0;这是一个很好的做法。
Put Connection timeout to 0. A value of 0 indicates no limit (an attempt to execute a command will wait indefinitely).
But do not set connection timeout in connection string. Because an attempt to connect waits indefinitely. So you can use in your command like SqlCommand.CommandTimeout=0;This is the good practice.


这篇关于如何将连接超时设置为无穷大(直到命令完成)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆