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
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
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.