开始事务时SqlServer.Management.SMO.Server错误

Mal*_*are 5 c# sql-server smo transactions

使用SMO时出错.这段代码一直在VB.Net 4中运行,刚刚转移到C#,现在无法运行.

Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server(
    new Microsoft.SqlServer.Management.Common.ServerConnection(
    new System.Data.SqlClient.SqlConnection(connStr.ToString())));

server.ConnectionContext.Connect();
server.ConnectionContext.BeginTransaction(); // error here
Run Code Online (Sandbox Code Playgroud)

错误是:

在MARS批处理中启动的事务在批处理结束时仍处于活动状态.该事务被回滚.

除了SMO之外,没有其他与数据库的连接.

连接字符串是:

数据源= MYPC\SqlServer;初始目录= mytestdb;集成安全性=真;用户ID =;密码=; MultipleActiveResultSets = True

有没有人在使用SMO时看到此错误并知道是什么原因造成的?

Mal*_*are 8

从连接字符串中删除MARS修复了问题.

  • 这不是解决办法。MARS 的存在是有充分理由的,因此您可以在同一连接上并行运行多个批次。 (6认同)