Are there any differences in the SMO ServerConnection transaction methods compared to using the SqlConnectionObject property?

I use SMO to create databases and tables on SQL Server. I want to do this in a transaction. Are both of these methods valid and equivalent:

First method:

Server server;
//...
server.ConnectionContext.BeginTransaction();
//...
server.ConnectionContext.CommitTransaction();

Second method:

Server server;
// ...
SqlConnection conn = server.ConnectionContext.SqlConnectionObject;
SqlTransaction trans = conn.BeginTransaction();
// ...
trans.Commit();
+3
source share
1 answer

These two are equivalent. Using the SqlTransaction object allows you to place a transaction in the field using:

using(SqlTransaction  trn = conn.BeginTransaction ())
{
 ...
 trn.Commit ();
}

This is the best template for exceptions.

+3
source

Source: https://habr.com/ru/post/1750388/


All Articles