c# - How .NET Transactions are working on Sql Server Database When conducted a small analysis -
I have a simple test transaction works to understand .net
Sample Code On which my transaction has been tested
_sqlHelper = new SqlHelper (true); {_sqlHelper.ExecuteNonQuery (Try SpName.sp_UpdateRoomStatus.ToString (), Parameters. SQLParam & lt; int? & Gt; ("Department ID", try this Department ID, SqlDbType.Int); _sqlHelper.ExecuteNonQuery (SpName.sp_UpdateRoomStatus .ToString (), parameter. SQLParam & lt; int? & Gt; ( "Vibagnirdec" it. DepartmentId, SqlDbType.Int)); _sqlHelper.CommitTransaction ();} catch (SqlHelperException ex) {_sqlHelper.RollBackTransaction (); }
test the details about
when I write new SqlHelper (true); start a new transaction internal And the connection is made and the database is created New is opened.
_sqlHelper.ExecuteNonQuery (SpName.sp_UpdateRoomStatus.ToString (), parameter. SQLParam & lt; int? & Gt; ( "Vibagnirdeshit" it. DepartmentId, SqlDbType.Int );;
The function now executes my process and changes the database.
I have twice to execute the process twice The only function call is written. This process is to merge into the database. In this process there are 3 included questions in 3 different tables. Now I have marked the breakpoint on the function calls.
As soon as the control comes on 1 breakpoint, I simply facilitate its processing which means that the first process has been entered.
Now I was on my LAN DB remote system so the wire means that the connection is lost. Therefore, the transaction is rollback.
Now that I have the whole process has been found in the consistent position I data to verify the database after the completion of so proving that work transactions
I'm confused at this moment in that where it was before the procedure call a real entry, because successfully implemented about the process was running how are advised to SQL server transaction and rollback Is not there.
It appears that the transaction was established in a database informing the connection in which the transaction occurs and it should be rolled
The database knows that the connection and change should be in the transaction - the actual change and the original data in the database transaction log Are stored. When the transaction is not done properly and the connection is lost, the database automatically rolls back the transaction.
Actually, in SqlTransactions (not distributed) .net does not cunning anything, it is all controlled by the database.
Comments
Post a Comment