C# Windows Server 2008 R2上的连接超时=0
好的,我有一个用C语言编写的程序,它通过一系列存储过程调用从SQL Server 2008获取一些信息。 我的连接字符串:C# Windows Server 2008 R2上的连接超时=0,c#,sql,sql-server,sql-server-2008,C#,Sql,Sql Server,Sql Server 2008,好的,我有一个用C语言编写的程序,它通过一系列存储过程调用从SQL Server 2008获取一些信息。 我的连接字符串: Data Source={0};Initial Catalog={1}; Integrated Security=True; Connection Timeout=0 {0}和{1}由变量填充 超时时间为零,因为信息可能非常庞大,获取它可能需要一些时间。 第一个过程运行平稳并返回其结果,但第二个过程只是停止程序,它永远不会醒来,它不会冻结,它只是在等待查询无限期执行。有趣
Data Source={0};Initial Catalog={1}; Integrated Security=True; Connection Timeout=0
{0}和{1}由变量填充超时时间为零,因为信息可能非常庞大,获取它可能需要一些时间。
第一个过程运行平稳并返回其结果,但第二个过程只是停止程序,它永远不会醒来,它不会冻结,它只是在等待查询无限期执行。有趣的是,当我在我的机器(Windows 7)上运行此程序时,一切正常(执行需要4秒),但在服务器上(Windows Server 2008 R2)我遇到了这种奇怪的行为。我设法解决了连接超时更改为其他数字(如15)的问题,但问题是为什么?
我的代码:
第一步: 第二步: 从MSDN:
You can set the amount of time a connection waits to time out by using the ConnectTimeout or Connection Timeout keywords in the connection string.
A value of 0 indicates no limit, and should be avoided in a ConnectionString because an attempt to connect waits indefinitely.
更多信息我知道。我的存储过程在Windows 7上4秒钟内执行,超时=0
static DataTable GetSql(string sp_name, params string[] vars)
{
SqlConnection.ClearAllPools(); //added this hoping it'd help - it didn't
DataTable DT = new DataTable();
SqlConnection conn = new SqlConnection(ConnectionString);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sp_name, conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.CommandTimeout = 0; //unlimited
da.SelectCommand.Parameters.AddWithValue("@date_b_d", vars[0]);
da.SelectCommand.Parameters.AddWithValue("@broker_id_s", vars[1]);
da.SelectCommand.Parameters.AddWithValue("@dogovor_id_s", vars[2]);
DataSet ds = new DataSet();
da.Fill(ds, "orders_list");
DT = ds.Tables["orders_list"];
return DT;
}
You can set the amount of time a connection waits to time out by using the ConnectTimeout or Connection Timeout keywords in the connection string.
A value of 0 indicates no limit, and should be avoided in a ConnectionString because an attempt to connect waits indefinitely.