Search code examples
c#sql-servertransactionssmo

SqlServer.Management.SMO.Server error when beginning transaction


Having an error when using SMO. This code has been working in VB.Net 4 and was just moved to C# and is now not functioning.

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

Error is :

A transaction that was started in a MARS batch is still active at the end of the batch. The transaction is rolled back.

There are no other connections to the database other than the SMO.

The connection string is:

Data Source=MYPC\SqlServer;Initial Catalog=mytestdb;Integrated Security=True;User ID=;Password=;MultipleActiveResultSets=True

Has anyone seen this error when using SMO and knows what is causing it?


Solution

  • Removing the MARS from the connection string fixed the problem.