FIX: The OdbcConnection object does not report an error when you specify a transaction isolation level that is not supported by the data source in the .NET Framework 2.0 (917752)



The information in this article applies to:

  • Microsoft .NET Framework 2.0

SYMPTOMS

Consider the following scenario. You use the Microsoft .NET Framework Data Provider for ODBC in the .NET Framework 2.0 to connect to a data source in your application. You then use the BeginTransaction method of the OdbcConnection object to start a transaction. You specify a transaction isolation level that is not supported by the data source for the transaction. In this scenario, the OdbcException exception does not occur as expected. However, the exception occurs as expected when you use the .NET Framework 1.1.

CAUSE

This problem occurs because the BeginTransaction method does not report the ODBC error (SQL_ERROR) that the SQLSetConnectAttr function returns. Autocommit mode is the default transaction management mode for the .NET Framework Data Provider for ODBC. The data provider only turns off Autocommit mode when the transaction isolation level is set correctly. Therefore, if you specify an incorrect transaction isolation level, the transaction does not work. If you call the Commit method or the Rollback method, they are invalid. The Commit method and the Rollback method do not report the ODBC error (SQL_ERROR).

RESOLUTION

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next NET Framework 2.0 Service Pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

Prerequisites

To apply this hotfix, you must have the Microsoft support files that are described in the following Microsoft Knowledge Base article installed on your computer:

916002 FIX: Error message when you try to use the SqlClient class in an ADO.NET 2.0-based application to connect to an instance of SQL Server 2005: "New request is not allowed to start because it should come with valid transaction descriptor"

Restart requirement

You do not have to restart the computer after you apply this hotfix.

Registry information

You do not have to change the registry.

Hotfix file information

This hotfix contains only those files that are required to correct the issues that this article lists. This hotfix may not contain all of the files that you must have to fully update a product to the latest build. The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.

.NET Framework 2.0 32-bit version

File nameFile versionFile sizeDateTimePlatform
Mscordacwks.dll2.0.50727.158800,76824-May-200614:59x86
Mscorlib.dll2.0.50727.1584,317,18424-May-200614:59x86
Mscorwks.dll2.0.50727.1585,623,29624-May-200614:59x86
Sos.dll2.0.50727.158377,34424-May-200614:59x86
System.data.dll2.0.50727.1582,893,82424-May-200614:59x86

.NET Framework 2.0 x64-based version

File nameFile versionFile sizeDateTimePlatform
Mscordacwks.dll2.0.50727.1581,597,44024-May-200606:09x64
Mscorlib.dll2.0.50727.1583,956,73624-May-200611:25x64
Mscorwks.dll2.0.50727.15810,306,04824-May-200606:05x64
Sos.dll2.0.50727.158476,16024-May-200606:15x64
System.data.dll2.0.50727.1582,959,87224-May-200611:25x64

.NET Framework 2.0 Itanium architecture version

File nameFile versionFile sizeDateTimePlatform
Mscordacwks.dll2.0.50727.1582,710,01624-May-200606:14IA-64
Mscorlib.dll2.0.50727.1583,956,73624-May-200612:03IA-64
Mscorwks.dll2.0.50727.15821,260,28824-May-200606:11IA-64
Sos.dll2.0.50727.158857,08824-May-200606:22IA-64
System.data.dll2.0.50727.1583,102,20824-May-200612:03IA-64

WORKAROUND

To work around this problem, make sure that you use the correct transaction isolation level. You can add code to the application to verify whether the transaction level is correct and to throw an exception in your code.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

For more information about the naming schema for Microsoft SQL Server updates, click the following article number to view the article in the Microsoft Knowledge Base:

822499 New naming schema for Microsoft SQL Server software update packages


For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates

MORE INFORMATION

This problem may cause data corruption because you cannot use the Rollback method. For example, you can specify an incorrect transaction level. You expect a rollback to occur if data corruption occurs. However, the rollback does not occur. Because the Commit method does not report the error, data corruption may occur because the data may not have been committed as expected.

Steps to reproduce the problem

  1. Create a Microsoft Access data file (.mdb), and then create a table that contains two columns. Assume that the data file is saved in the d:\db1.mdb folder and that the table name is T1. Assume that the two columns are named C1 and C2.
  2. Insert some records into the T1 table.
  3. Create a C# project by using Microsoft Visual Studio 2005, and then paste the following code into a method.
    string cnstr = @"Driver={Microsoft Access Driver (*.mdb)};DBQ=d:\db1.mdb;UID=Admin;PWD=;"
    OdbcConnection cn = new OdbcConnection(cnstr);
    cn.Open();
    System.Diagnostics.Debug.WriteLine("connected.");
    
    try
    {
    OdbcTransaction trn = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
    OdbcCommand cmd = new OdbcCommand("select * from T1", C1, C2);
    OdbcDataReader dr;
    dr = cmd.ExecuteReader();
    while (dr.Read())
    {
    System.Diagnostics.Debug.WriteLine(dr[1].ToString());
    }
    dr.Close();
    trn.Commit();
    }
    catch (OdbcException odbcex)
    {
    System.Diagnostics.Debug.WriteLine(odbcex.Message);
    System.Diagnostics.Debug.WriteLine(odbcex.StackTrace);
    }
    cn.Close();
    cn = null;
    
  4. Run the application, and make sure that you called the method.
After you complete these steps, you will notice that no exception occurs.

Modification Type:MajorLast Reviewed:6/20/2006
Keywords:kbprb kbtshoot kbExpertiseAdvanced KB917752 kbAudDeveloper