相关疑难解决方法(0)

我真的需要使用"SET XACT_ABORT ON"吗?

如果你小心并且在所有内容周围使用TRY-CATCH,并且你真的需要使用以下错误回滚:

SET XACT_ABORT ON
Run Code Online (Sandbox Code Playgroud)

换句话说,是否有任何错误,TRY-CATCH将错过SET XACT_ABORT ON将处理?

sql-server error-handling transactions sql-server-2005

25
推荐指数
1
解决办法
2万
查看次数

C# - 即使将 CommandTimeout 设置为在设定时间后终止查询,查询仍在 SQL Server 数据库中运行

在我的 C# 代码中,我使用CommandTimeout函数来确保任何执行时间超过 30 秒的查询都从服务器和数据库中终止。但是,当列出数据库上当前正在运行的查询时,设置为 30 秒后取消的查询运行时间远远超过 30 秒

using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
    SqlCommand sqlCommand = new SqlCommand(query, connection);

    //Set Timeout to 30s
    sqlCommand.CommandTimeout = 30;
    SqlDataAdapter da = new SqlDataAdapter(sqlCommand);

    da.Fill(response);
    connection.Close();
    da.Dispose();
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

为什么查询仍在数据库中运行?我现在唯一的选择是从服务器发送另一个查询以在 30 秒后终止查询(KILL [session_id])?

编辑:此查询返回了 300Mb 的数据。

c# sql-server

3
推荐指数
1
解决办法
2243
查看次数