gpt4 book ai didi

c# - 使用远程 sql server 进行批量插入时出现异常

转载 作者:太空宇宙 更新时间:2023-11-03 13:55:24 31 4
gpt4 key购买 nike

我正在调用一个 rest 完整服务,该服务依次在 sql server 数据库中执行批量插入。当休息服务器和数据库服务器在同一台机器上时,一切正常,但在远程数据库服务器的情况下,会遇到以下异常。

System.InvalidOperationException: The transaction associated with the current 
connection has completed but has not been disposed.
The transaction must be disposed before the connection can be used to
execute SQL statements.

我正在使用以下交易。

TransactionOptions tOptions = new TransactionOptions();
tOptions.IsolationLevel = IsolationLevel.ReadCommitted;
//This transaction is required here as it checks for all db operations.
using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, tOptions))
{
//DB operations....
transactionScope.Complete();
}

最佳答案

在我的 IIS 服务器上配置 Windows MSDTC 服务就成功了。

以下链接显示了如何配置 MSDTC。

http://www.deepakkapoor.net/turn-on-msdtc-windows-7/

关于c# - 使用远程 sql server 进行批量插入时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12399995/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com