.net - SQL Scripts from dotnet with transactions -


I am trying to execute SQL scripts from dotnet (c #) but can be geo statement in SQL scripts and I would like to be able to wrap the collection of scripts in one transaction.

I got the question and the accepted answer I got to deal with the Geo Statement, but if I use an initial behavior then it will be Invalid Operation Exposure on the "New Server Connection" line .

  SqlConnection connection = new SqlConnection (connectionString); Connection.Open (); SqlTransaction transaction = connection.BeginTransaction (transactionName); ServerConnection Server Connection = New Server Connection (Connection);  

I'm running it against SQL Server 2005.

I found a way, after trying several combinations, the simplest thing done ... < / P>

Good assuming that you are using TransactionScope object

  (different transaction scope = new transaction scope (transaction scopap Essentials, New Transaction Options {Isolation Level = Isolation. SqlServerInstance.ConnectionContext.StatementTimeout = int.MaxValue; // This Line Creates Magic =) sqlServerInstance.ConnectionContext.SqlConnectionObject.EnlistTransaction (Transaction.Current); sqlServerInstance.Co NnectionContext.ExecuteNonQuery (scriptContent);}  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -