tags:

views:

23

answers:

1

Hi


If we’re using client-initiated Ado.Net transactions, then when we try to execute a command that is not a part of current transaction while the transaction is underway, we’ll receive an error. Why is that?


thanx

+1  A: 

You can't execute a command that is 'not part of the current transaction'. Once a SqlTransaction was started, the BEGIN TRANSACITON statement was executed and the server has enroled your session in a transaction. any new statement comming on the same session will be part of the transaction. The ADO.Net SqlClient enforces this by requiring you to assign the proper SqlTransaction to the SqlCommand.

If you need to execute a statement outside the current transaction, you need to get a new connection to the database and execute your statement on it.

BTW, you said ADO.Net transactions and I took your work for it, the.Net System.Transactions components have some different behaviour.

Remus Rusanu
1) Is there a reason Ado.Net doesn't allow you to execute a command which is not part of current transaction?2) "BTW, you said ADO.Net transactions and I took your work for it, the.Net System.Transactions components have some different behaviour." I was referring to transactions represented by SqlTransaction object. Why are there additional, non Ado.Net related transation components?
carewithl
1) The limitation is imposed by servers and ADO.Net simply models the same limitation. 2) System.Transactions, see http://msdn.microsoft.com/en-us/library/system.transactions.aspx
Remus Rusanu
thank you for helping me out
carewithl