使用 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
错误是:
A transaction that was started in a MARS batch is still active at the end of the batch. The transaction is rolled back.
除了 SMO 之外,没有与数据库的其他连接。
连接字符串是:
Data Source=MYPC\SqlServer;Initial Catalog=mytestdb;Integrated Security=True;User ID=;Password=;MultipleActiveResultSets=True
有没有人在使用 SMO 时看到过这个错误并且知道是什么原因造成的?
最佳答案
从连接字符串中删除 MARS 解决了问题。
关于c# - 开始事务时出现 SqlServer.Management.SMO.Server 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9744089/