About SqlCommand & SqlConnection Timeout expired
2010-06-20 17:47
381 查看
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" 或者 SqlClient Class , 你在执行一个很费时的SQL 操作时候,可能就会碰到下面的超时异常。
---------------------------
---------------------------
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
---------------------------
OK
---------------------------
你会说,我在连接字符串中已经 设置了 Connect Timeout=80000 ,并且数据库中超时连接也是设置的值是一个很大的值。为啥到了30秒,仍然超时了呢??
这是因为:
你的设置并没有问题,是你混淆了 SqlCommand.CommandTimeout 和 SqlConnection.ConnectionTimeout 这两个的区别了。
你的连接字符串中的超时只是设置的 SqlConnection.ConnectionTimeout 的值,而不是设置的 SqlCommand.CommandTimeout 的值。
SqlHelper 中并没有 SqlCommand.CommandTimeout 的相关设置。需要你自己设置。
下面是两个的比较:
SqlCommand.CommandTimeout
获取或设置在终止执行命令的尝试并生成错误之前的等待时间。
等待命令执行的时间(以秒为单位)。默认为 30 秒。
SqlConnection.ConnectionTimeout
获取在尝试建立连接时终止尝试并生成错误之前所等待的时间。
等待连接打开的时间(以秒为单位)。默认值为 15 秒。
一些更详细的对这个问题的描述看:
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=357
这个问题可以算是 SqlHelper 设计的时候,一个考虑不周的地方吧。
SqlCommand.CommandTimeout 的默认值是30,对于我写的大多数程序来说,这个值足够了。所以一直都没有发现SqlHelper的这个问题。今天在查本地一台比较差的机子上生成一个超长帖子(近4000个回复)无响应的问题时候,才发现SQLHelper 存在的这个问题。
如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" 或者 SqlClient Class , 你在执行一个很费时的SQL 操作时候,可能就会碰到下面的超时异常。
---------------------------
---------------------------
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
---------------------------
OK
---------------------------
你会说,我在连接字符串中已经 设置了 Connect Timeout=80000 ,并且数据库中超时连接也是设置的值是一个很大的值。为啥到了30秒,仍然超时了呢??
这是因为:
你的设置并没有问题,是你混淆了 SqlCommand.CommandTimeout 和 SqlConnection.ConnectionTimeout 这两个的区别了。
你的连接字符串中的超时只是设置的 SqlConnection.ConnectionTimeout 的值,而不是设置的 SqlCommand.CommandTimeout 的值。
SqlHelper 中并没有 SqlCommand.CommandTimeout 的相关设置。需要你自己设置。
下面是两个的比较:
SqlCommand.CommandTimeout
获取或设置在终止执行命令的尝试并生成错误之前的等待时间。
等待命令执行的时间(以秒为单位)。默认为 30 秒。
SqlConnection.ConnectionTimeout
获取在尝试建立连接时终止尝试并生成错误之前所等待的时间。
等待连接打开的时间(以秒为单位)。默认值为 15 秒。
一些更详细的对这个问题的描述看:
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=357
这个问题可以算是 SqlHelper 设计的时候,一个考虑不周的地方吧。
SqlCommand.CommandTimeout 的默认值是30,对于我写的大多数程序来说,这个值足够了。所以一直都没有发现SqlHelper的这个问题。今天在查本地一台比较差的机子上生成一个超长帖子(近4000个回复)无响应的问题时候,才发现SQLHelper 存在的这个问题。
相关文章推荐
- SqlConnection.ConnectionTimeout 与 SqlCommand.CommandTimeout
- QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connect
- 网站错误记录:Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.
- QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connect
- mysql连接池和 "Timeout expired"异常
- ASP.NET连接 MS SQL Timeout expired. 问题的处理
- org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting
- CommandTimeout vs ConnectionTimeout
- Combining SqlConnection and SqlCommand in one Class in C#
- 连接池和 "Timeout expired"异常
- SQL Server Driver Timeout expired
- How to get details about patch applied in Oracle Applications by OAM & SQL?
- [ADO&VC一]使用ADO智能指针_ConnectionPtr,_CommandPtr及_RecordsetPtr
- QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connect
- QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection'解决办法
- 连接池和 "Timeout expired"异常
- Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.
- MS SQL错误:SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems
- Connection Pooling and the "Timeout expired" exception FAQ
- Login failed for user ''.Reason:Not associated with a trusted SQL Server connection.