SqlServer.Management.SMO.Server error when beginning transaction
Asked Answered
S

1

8

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?

Supreme answered 16/3, 2012 at 20:29 Comment(3)
Have you tried disabling MARS (MultipleActiveResultSets=False)?Ked
I guess disabling MARS will fix this but I'd hate just changing settings until the code starts to work.Angeles
removing the MARS from the connection string fixed the problem.Bookstore
S
9

Removing the MARS from the connection string fixed the problem.

Supreme answered 24/8, 2012 at 18:3 Comment(1)
That's not a fix. MARS is there a for a very good reason, so you can run multiple batches in parallel on the same connection.Dare

© 2022 - 2024 — McMap. All rights reserved.