Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 使用语句需要很长时间,有时会超时_Sql Server_Ado.net - Fatal编程技术网

Sql server 使用语句需要很长时间,有时会超时

Sql server 使用语句需要很长时间,有时会超时,sql-server,ado.net,Sql Server,Ado.net,我是ASP.NET新手。我想我不知道什么时候使用USING语句。当我在我的代码中尝试它时,下面是一个示例。它需要很长时间,有时会超时。当我不用电脑跑步时,效果很好 ... Some codes up here. Open DB Connection Execute.... cmdinsert.CommandText = insertcommand; cmdinsert.ExecuteNonQuery(); // --- Now calling the stored procedure to

我是ASP.NET新手。我想我不知道什么时候使用USING语句。当我在我的代码中尝试它时,下面是一个示例。它需要很长时间,有时会超时。当我不用电脑跑步时,效果很好

... Some codes up here. Open DB Connection Execute....
cmdinsert.CommandText = insertcommand;
cmdinsert.ExecuteNonQuery();


// --- Now calling the stored procedure to process all this imported items.
SqlCommand command = new SqlCommand("Import_EvaluationMatch", connSQL, trans);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add("@RefNum", SqlDbType.Int).Value = RefNum;
    command.ExecuteNonQuery();
trans.Commit();
connSQL.Close();
有人能澄清一下使用声明吗?我什么时候该用,什么时候不该用

此代码花费了很长时间,并且超时。 ... 这里有一些代码。打开数据库连接执行

cmdinsert.CommandText = insertcommand;
cmdinsert.ExecuteNonQuery();

Using (SqlCommand command = new SqlCommand("Import_EvaluationMatch", connSQL, trans))
    {
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add("@RefNum", SqlDbType.Int).Value = RefNum;
    command.ExecuteNonQuery();
    }
trans.Commit();
connSQL.Close();

Response.Write("Import Successfully");
Response.Redirect("Default.aspx");
Response.End();
删除了USING语句,它工作正常

... Some codes up here. Open DB Connection Execute....
cmdinsert.CommandText = insertcommand;
cmdinsert.ExecuteNonQuery();


// --- Now calling the stored procedure to process all this imported items.
SqlCommand command = new SqlCommand("Import_EvaluationMatch", connSQL, trans);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add("@RefNum", SqlDbType.Int).Value = RefNum;
    command.ExecuteNonQuery();
trans.Commit();
connSQL.Close();

using
语句不会占用任何时间。花费时间的是清理
SqlCommand
。当您使用
using
语句时,清理将以串联方式进行。当您不使用它时,每当垃圾收集器决定清理时,就会随机进行清理

这是一个“现在付钱给我,或者以后再付钱”的例子


问题是您的
Import\u EvaluationMatch
存储过程花费的时间太长。

谢谢您的回复。嗯,我运行了Import_EvaluationMatch,速度非常快。所以清理工作真的花了那么长时间?显然,是的。也许这与您对事务的使用有关。尝试不使用事务,看看它有多快(仅作为一种toubleshooting技术)。