April 30, 2009 at 4:53 pm
I am trying to udpate two tables within a transaction defined in .Net. The actual code snippet is below. When I get to the Commit, I get the 'This SqlTransaction has completed' message.
I know the reason I get the message is that the transaction is being committed to the database. I can see the updates in the tables every time I run the application.
The stored proc inserts a row into two separate tables. It has no 'Begin trans' and no commit or rollback statements.
So I'm not sure why the commit is occurring. Any help is appreciated. Thanks!
John F.
--------- .net code ------------------------
transaction = connection.BeginTransaction(IsolationLevel.Serializable);
DbCommand command = _db.GetStoredProcCommand(spName);
command.CommandTimeout = 0;
int response = _db.ExecuteNonQuery(command);
transaction.Commit();
May 4, 2009 at 12:12 pm
For future reference:
I was able to solve this pretty simply. I just needed to add the transaction as a parameter on the ExecuteNonQuery. Setting the transaction property of DbCommand wasn't sufficient.
--------- .net code ------------------------
transaction = connection.BeginTransaction(IsolationLevel.Serializable);
DbCommand command = _db.GetStoredProcCommand(spName);
command.CommandTimeout = 0;
int response = _db.ExecuteNonQuery(command, transaction);
transaction.Commit();
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply