BUG: BeginTransaction() changes the isolation level for subsequent transactions (309544)
The information in this article applies to:
- Microsoft .NET Framework
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft ADO.NET (included with the .NET Framework 1.1)
- Microsoft Windows .NET Framework 1.1
This article was previously published under Q309544 SYMPTOMS 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. RESOLUTION Use one of the following workarounds to set the isolation
level back to the default IsolationLevel.ReadCommitted:
- 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:
[Microsoft Visual Basic .NET]
Dim resetCMD As New SqlCommand("SET TRANSACTION ISOLATION LEVEL READ COMMITTED", sqlConn)
resetCMD.ExecuteNonQuery()
[Microsoft Visual C# .NET]
SqlCommand resetCMD = new SqlCommand("SET TRANSACTION ISOLATION LEVEL READ COMMITTED", sqlConn);
resetCMD.ExecuteNonQuery();
[Microsoft Visual C++ .NET]
SqlCommand resetCMD = new SqlCommand("SET TRANSACTION ISOLATION LEVEL READ COMMITTED", sqlConn);
resetCMD.ExecuteNonQuery();
[Microsoft JScript .NET]
var resetCMD:SqlCommand = new SqlCommand("SET TRANSACTION ISOLATION LEVEL READ COMMITTED", sqlConn);
resetCMD.ExecuteNonQuery();
- Call BeginTransaction, and immediately follow this with Commit. The default is to open with IsolationLevel.ReadCommitted; however, you do not have to specify this value explicitly. For
example:
[Visual Basic .NET]
Dim tempTrans As SqlTransaction = sqlConn.BeginTransaction()
tempTrans.Commit()
[Visual C# .NET]
SqlTransaction tempTrans = sqlConn.BeginTransaction();
tempTrans.Commit();
[Visual C++ .NET]
SqlTransaction tempTrans = sqlConn.BeginTransaction();
tempTrans.Commit();
[JScript .NET]
var tempTrans:SqlTransaction = sqlConn.BeginTransaction();
tempTrans.Commit();
STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 3/13/2006 |
---|
Keywords: | kbtshoot kbbug kbpending kbreadme kbSqlClient KB309544 kbAudDeveloper |
---|
|