简体   繁体   English

简单的更新命令导致SqlException执行超时过期

[英]Simple update command causes SqlException Execution Timeout Expired

I have an application which converts a mssql-db (source) to another mssql-db (target). 我有一个将mssql-db(源)转换为另一个mssql-db(目标)的应用程序。 For every table in my source i basically get all rows and make an insert for every row to my target. 对于我的源代码中的每个表,我基本上都获得了所有行,并为目标行的每一行插入了一个插入。 I run a simple query which updates the source-row to store the target-table and target-id of the records which get inserted to the target-db: 我运行一个简单的查询,该查询更新了源行以存储插入到target-db中的记录的target-table和target-id:

var commandText = $"UPDATE SOURCE_TABLE SET SOURCE_TABLE.TARGET_ID = '{target_id}', SOURCE_TABLE.TARGET_TBL = '{target_table}' WHERE SOURCE_TABLE.ID = '{id}'";

base.Source.ExecuteNonQuery(commandText);

This runs perfectly fine until i try to update the source-row of a specific table. 在我尝试更新特定表的源行之前,这运行得很好。 I get an SqlException Execution Timeout Expired . 我得到一个SqlException Execution Timeout Expired

I have checked the variables target_id, target_table and id they are all filled with valid values. 我已经检查了变量target_id,target_table和id,它们都填充有有效值。 I have disabled all triggers and the id-field is primary key. 我已禁用所有触发器,并且id字段是主键。

When i run this command via management-studio, there is not problem. 当我通过管理工作室运行此命令时,没有问题。 Doesnt even take a second to process. 甚至不花一点时间来处理。


I have used the activity-monitor from management-studio to monitor when the sql runs. 我使用了来自management-studio的活动监视器来监视sql的运行时间。 The databases with the red box are the target-db. 带有红色框的数据库是target-db。 活动监控器 Every single peak in the second diagramm ("Wartende Tasks" = "waiting tasks"). 第二个图表中的每个峰值(“ Wartende任务” =“等待任务”)。 Stands for one time the query has been tried to execute. 表示尝试执行查询一次。


This is how the command is executed: 这是命令的执行方式:

public int ExecuteNonQuery(string commandText)
{
    using (var connection = this.CreateConnection()) // new SqlConnection(CONNECTION_STRING)
    {
        connection.Open();
        using (var command = connection.CreateCommand())
        {
            command.CommandText = commandText;

            return command.ExecuteNonQuery();
        }
    }
}

Can you try to add a begin transaction before the query then a commit transaction after the query? 您可以尝试在查询之前添加开始事务,然后在查询之后添加提交事务吗? I would try this for both the insert on the source and the update on the target. 我会同时尝试在源上的插入和目标上的更新。

The problem was, the process which makes the update on the source is blocked by the process which makes select on the source. 问题是,在源上进行更新的过程被在源上进行选择的过程阻塞了。 I had to wrap these into an transaction to use the IsolationLevel.ReadUncommitted . 我必须将它们包装到事务中才能使用IsolationLevel.ReadUncommitted Now it works. 现在可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Entity Framework Core 3.0 查询导致“SqlException: 'Execution Timeout Expired'”和 tempdb 变满。 适用于 EF Core 2.2.6 - Entity Framework Core 3.0 query causes “SqlException: 'Execution Timeout Expired'” and tempdb become full. Works with EF Core 2.2.6 SqlException执行超时在执行轻量级查询时过期 - SqlException Execution Timeout Expired when executing lightweight query System.Data.SqlClient.SqlException:'执行超时已过期 - System.Data.SqlClient.SqlException: 'Execution Timeout Expired 简单的LINQ to Entities更新引发“超时已过期” - Simple LINQ to Entities update throwing 'Timeout expired' SQL 服务器 Microsoft.Data.SqlClient.SqlException (0x80131904):执行超时在 azure 上过期 - SQL server Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired on azure SqlException超时过期到Dot Net Core 2.2中 - SqlException Timeout expired into Dot net core 2.2 System.Data.SqlClient.SqlException:超时已过期 - System.Data.SqlClient.SqlException: Timeout expired 执行超时在 Visual Studio 中过期 - Execution Timeout Expired In Visual Studio 执行超时在插入数据库然后使用 EF Core 更新数据库完成后过期 - Execution Timeout Expired after inserting into database and then using EF Core to update database with completion 执行非查询时SqlException'timeout expired',但插入了数据 - SqlException 'timeout expired' when executing nonquery, but data are inserted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM