这是一段不好的代码片段:
string storedProcedure = "sp3111Commissions";
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand()) {
string ConnectionString = CMSLayers.DataLayer.Universal.GetConnectionString();
ConnectionString =
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection()) {
//Response.Write(EndDate2.ToString());
//Response.End();
conn.ConnectionString = ConnectionString;
//Response.Write(ConnectionString); Response.End(); return null;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.CommandText = storedProcedure;
cmd.Parameters.Add("@ShopID", System.Data.SqlDbType.Int);
cmd.Parameters["@ShopID"].Value = ShopID;
cmd.Parameters.Add("@StartDate", System.Data.SqlDbType.DateTime);
cmd.Parameters["@StartDate"].Value = StartDate;
cmd.Parameters.Add("@EndDate", System.Data.SqlDbType.DateTime);
cmd.Parameters["@EndDate"].Value = EndDate;
cmd.Parameters.Add("@StartDate2", System.Data.SqlDbType.DateTime);
cmd.Parameters["@StartDate2"].Value = StartDate2;
cmd.Parameters.Add("@EndDate2", System.Data.SqlDbType.DateTime);
cmd.Parameters["@EndDate2"].Value = EndDate2;
cmd.CommandTimeout = 1380;
try
{
System.Data.DataSet ds;
using (System.Data.SqlClient.SqlDataAdapter da= new System.Data.SqlClient.SqlDataAdapter()) {
System.Data.DataTable Table = null;
conn.Open();
da.SelectCommand = cmd;
using (ds = new System.Data.DataSet()) {
da.Fill(ds);
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
Table = ds.Tables[0];
}
}
conn.Close();
return Table;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
}
发生的事情是它挂了大约 2 分钟,然后最终出现超时错误。但是,如果我在 SQL Server Management Studio 中使用完全相同的参数运行存储过程,则数据会立即返回。
“挂起”发生在“da.Fill(ds);” 线。有人有想法么?顺便说一下,这是 .NET 2.0