When you call the SqlConnection.BeginTransaction method and specify an isolation level in the IsolationLevel property, after the transaction is committed or rolled back, the IsolationLevel property is not reset to the default of IsolationLevel.ReadCommitted for subsequent commands. This can cause unexpected locking or cause the application to read the wrong version of a record. Use one of the following workarounds to set the isolation level back to the default IsolationLevel.ReadCommitted:
1.Close and re-open the connection. If you are using connection pooling (which is the default), make sure that you did not specify "connection reset=false" in the connect string. "Connection Reset" is "true" by default.
Run a SQL statement through a SqlCommand object to manually reset the transaction isolation level as follows
view sourceprint?
SqlCommand resetCMD = new SqlCommand("SET TRANSACTION ISOLATION LEVEL READ COMMITTED", sqlConn);
resetCMD.ExecuteNonQuery()
No comments:
Post a Comment