【发布时间】:2012-09-26 15:38:34
【问题描述】:
我有一个 .NET Windows 服务,它引用了一个调用 SQL Server 数据库的特定程序集。这些 SQL 调用的连接字符串被编码为从 ConfigurationManager.ConnectionStrings["myconnection"] 中提取。
在服务的安装目录中,我有一个配置文件,其中包含连接字符串“myconnection”,它最初没有连接超时值,并且长时间运行的查询在 30 秒后意外超时。但是,通过将“Connection Timeout=300”添加到连接字符串并重新启动服务,我们发现没有任何区别。
编辑:commandtimeout 属性设置为 300。示例如下:
SqlCommand _command = new SqlCommand(Sql, _con);
SqlDataReader _DR = _command.ExecuteReader();
_command.CommandTimeout = 300;
string _fieldValue;
string _columnValue;
while (_DR.Read()){ ... }
【问题讨论】:
-
The commandtimeout property is set to 30。我们应该相信什么? -
@GreenShepherd - 在调用 ExecuteReader 之前尝试更改 CommandTimeout。
标签: .net windows-services connection-string