短: 调用 transaction.Commit() 后,下一个操作失败,就好像事务未提交一样。
更多详情: 我们有一个线程运行对数据库的写入查询,其中一些被封装在一个事务中。 一段时间后运行较重的负载时,我们会遇到这样一种情况:提交事务后操作失败,并出现错误,表明事务正在进行中,根据提交后执行的操作,我们会收到以下错误之一:
下一个操作是“开始交易:
...Connection does not support parallel transactions...
下一个操作是插入/更新/删除
ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
通过调试器检查 Sql Connection 对象显示它包含一个“sqlInnerTransaction”对象,其父对象设置为 null。
我们确实知道对“Commit”的调用成功完成,没有出现错误。
运行 .net 4.0,SQL Server 2008 R2 SP2
最佳答案
查看此消息:
Connection does not support parallel transactions
不知道你们是不是在多线程中使用了一个连接对象?
连接不是线程安全的。您应该只在创建它们的线程中使用它们。
关于c# - SQL 事务提交使连接处于损坏状态 (c#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13687564/