I've always done transactions from within stored procedures but now I need to wrap a bunch of "dynamic" statements executed from code against sp_executesql
in a transaction.
Specifically I need the READ UNCOMMITED
isolation level for these in some cases (I know what that does, and yes, that's what I need). This is SQL2008.
My question is this: If I use the BeginTransaction()
method of my SqlConnection instance with the isolation level set to IsolationLevel.ReadUncommitted
will that have the same effect as if I executed a stored proc that has the READ UNCOMMITED
statement?
A transaction is a unit of work that is performed against a database. Transactions are units or sequences of work accomplished in a logical order, whether in a manual fashion by a user or automatically by some sort of a database program. A transaction is the propagation of one or more changes to the database.
If you need the set to fail or succeed as a whole then wrap it in a transaction. The classic example is transfer of money from a checking to a savings account - if the deposit fails then I want the withdrawal to fail. If data out of synch because of a developer mistake is OK then don't use transactions.
A transaction begins with the first executable SQL statement. A transaction ends when it is committed or rolled back, either explicitly with a COMMIT or ROLLBACK statement or implicitly when a DDL statement is issued.
Yes, it will.
The SqlConnection uses the SQL native client, and a call to BeginTransaction
causes exactly this to be sent to the server:
SET TRANSACTION ISOLATION LEVEL <WHATEVER>; BEGIN TRANSACTION;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With