Microsoft KB Archive/932491

= FIX: Data that is associated with a component that uses the System.Data object may become corrupted in an application that is built on the Microsoft .NET Framework 2.0 =

Article ID: 932491

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 2.0

-





SYMPTOMS
When you try to use a component in an application that is built on the Microsoft .NET Framework 2.0, data that is associated with the component may become corrupted. This problem occurs when the component uses a System.Data.DataSet object. When this problem occurs, you may experience one or more of the following issues:
 * When the AcceptChanges method in a DataView class is called, the record manager may become corrupted.
 * The computed values in an expression column may not be updated correctly.
 * When the DataTable.Select method is called by using multiple statements, an incorrect result may be returned.
 * The internal index of a DataTable object may become corrupted. Additionally, you receive a '13' error message.
 * When a Merge operation occurs, the record manager may become corrupted if the target row is in the edit state.
 * The internal index of a DataTable object may become corrupted. Additionally, you receive a '5' error message.



Download information
The following file is available for download from the Microsoft Download Center:

Download the 303313_intl_x64_zip.exe package or the 303314_intl_i386_zip.exe package or the 303315_intl_ia64_zip.exe package now.

Release Date: 6/20/2007

For more information about how to download Microsoft support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to obtain Microsoft support files from online services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file.

Hotfix information
A supported hotfix is now available from Microsoft. However, it is intended to correct only the problem that is described in this article. Apply it only 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 Microsoft .NET Framework 2.0 service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Customer Support Services to obtain the hotfix. For a complete list of Microsoft Customer Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

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
There are no prerequisites for installing this hotfix.

Restart requirement
You do not have to restart your computer after you apply this hotfix.

Hotfix replacement information
This hotfix does not replace any other hotfixes.

File information
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 item in Control Panel.

For Itanium-based computers


STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Issue 1: When the AcceptChanges method in a DataView class is called, the record manager may become corrupted
Record manager corruption may occur during a write operation from an event handler. When this occurs, a System.NullreferenceException exception may be raised. Additionally, when the application performs a write operation in a ListChanged event, index updates may occur in the incorrect order.

For example, consider the following scenario:   You use the following code in the application: using System; using System.ComponentModel; using System.Data;

class Test { private static DataRow _dr = null; private static bool _accept = false; public static void Main {       try { DataSet ds = new DataSet; DataTable dt = ds.Tables.Add(&quot;Customers&quot;); DataColumn c = dt.Columns.Add(&quot;Id&quot;, typeof(int)); dt.PrimaryKey = new DataColumn[] { c }; dt.Columns.Add(&quot;Name&quot;, typeof(string)); dt.Columns.Add(&quot;Age&quot;, typeof(int)); dt.Rows.Add(new object[] { 1, &quot;A&quot;, 10 }); dt.Rows.Add(new object[] { 2, &quot;B&quot;, 20 }); dt.Rows.Add(new object[] { 3, &quot;G&quot;, 30 }); dt.Rows.Add(new object[] { 4, &quot;H&quot;, 40 }); dt.Rows.Add(new object[] { 5, &quot;I&quot;, 50 });

ds.AcceptChanges; DataView dv = new DataView(dt); dv.Sort = &quot;Name ASC&quot;; dv.ListChanged += new ListChangedEventHandler(OnListChanged); _dr = dt.Rows[4]; _accept = true; _dr[&quot;Name&quot;] = &quot;C&quot;; _accept = false; _dr[&quot;Name&quot;] = &quot;D&quot;; _dr[&quot;Age&quot;] = 55; Console.WriteLine(dv[2][1]); } catch (Exception exc) { Console.WriteLine(exc); }   }    public static void OnListChanged(object sender, ListChangedEventArgs args) {       if (_dr != null && _accept) { _dr.AcceptChanges; }   } }  You run the application.

In this scenario, you receive an error message that resembles the following error message:

System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.DataView.IsOriginalVersion(Int32 index) at System.Data.DataRowView.get_Item(Int32 ndx) at Test.Main in c:\Work\bugs\newbug1\Test.cs:line 42

To work around this issue, do not perform any write operations in a ListChanged event. It is best to use the RowChanged event instead of the ListChanged event.

Issue 2: The computed values in an expression column may not be updated correctly
When you try to compute the values of an expression column in a DataSet object, and the expression column is part of a relationship, the computed values of the expression column may not be updated correctly. For example, consider the following scenario:   You use the following code in the application: using System; using System.ComponentModel; using System.Data;

class Test { public static void Main {       try { DataSet ds = new DataSet;

DataTable dt1 = ds.Tables.Add(&quot;T1&quot;); dt1.Columns.Add(&quot;CustId&quot;, typeof(int)); dt1.Columns.Add(&quot;CustName&quot;, typeof(string));

DataTable dt2 = ds.Tables.Add(&quot;T2&quot;); dt2.Columns.Add(&quot;EmpId&quot;, typeof(int)); DataColumn dcEmpName = dt2.Columns.Add(&quot;EmpName&quot;, typeof(string)); DataColumn dcMgrName = dt2.Columns.Add(&quot;MgrName&quot;, typeof(string)); DataColumn dcReports = dt2.Columns.Add(&quot;NumberOfReports&quot;, typeof(int)); DataRelation rel1 = ds.Relations.Add(&quot;T1T2&quot;, dt1.Columns[&quot;CustId&quot;], dt2.Columns[&quot;EmpId&quot;], false); DataRelation rel2 = ds.Relations.Add(&quot;T2T2&quot;, dt2.Columns[&quot;EmpName&quot;], dt2.Columns[&quot;MgrName&quot;], false);

dcEmpName.Expression = &quot;Parent(T1T2).CustName&quot;; dcMgrName.Expression = &quot;Parent(T1T2).CustName&quot;;

//Each person is a manager to himself. dcReports.Expression = &quot;Count(Child(T2T2).EmpName)&quot;;

AddRow(dt1, 1, &quot;N1&quot;); AddRow(dt1, 2, &quot;N2&quot;); AddRow(dt1, 3, &quot;N3&quot;);

AddRow(dt2, 1); AddRow(dt2, 2); AddRow(dt2, 3);

Console.WriteLine(ds.GetXml);

dt1.Rows[0][&quot;CustName&quot;] = &quot;N4&quot;;

Console.WriteLine(ds.GetXml); } catch (Exception exc) { Console.WriteLine(exc); }   }

public static void AddRow(DataTable dt, params object[] objArr) {       Console.WriteLine(&quot;Adding row to table {0}&quot;, dt.TableName); dt.Rows.Add(objArr); } }  You run the application.</ol>

In this scenario, you receive the following output: <NewDataSet> <T1> <CustId>1</CustId> <CustName>N4</CustName> </T1> <T1> <CustId>2</CustId> <CustName>N2</CustName> </T1> <T1> <CustId>3</CustId> <CustName>N3</CustName> </T1> <T2> <EmpId>1</EmpId> <EmpName>N4</EmpName> <MgrName>N4</MgrName> <NumberOfReports>0</NumberOfReports> </T2> <T2> <EmpId>2</EmpId> <EmpName>N2</EmpName> <MgrName>N2</MgrName> <NumberOfReports>1</NumberOfReports> </T2> <T2> <EmpId>3</EmpId> <EmpName>N3</EmpName> <MgrName>N3</MgrName> <NumberOfReports>1</NumberOfReports> </T2> </NewDataSet> In this output, the NumberOfReports element in the first T2 element contains the incorrect value of 0 instead of 1.

Issue 3: When the DataTable.Select method is called by using multiple statements, an incorrect result may be returned
When you use the Select method of a DataTable object together with the AND clause to retrieve data for multiple statements, the Select method may return an incorrect result. For example, the following code returns an incorrect result: string filter = &quot;(NOT ColTwo = 1) AND (ColOne = 2)&quot;; DataTable.Select(filter); However, the following code returns the correct result: string filter = &quot;NOT ColTwo = 1 AND ColOne = 2&quot;; DataTable.Select(filter); Additionally, consider the following scenario:   You use the following code in the application: public static void Main { DataTable table = new DataTable; table.Columns.Add(&quot;ColID&quot;, typeof(int)); table.Columns.Add(&quot;ColOne&quot;, typeof(int)); table.Columns.Add(&quot;ColTwo&quot;, typeof(int)); table.Rows.Add(new object[] { 1, 1, 1 }); table.Rows.Add(new object[] { 2, 1, 2 }); table.Rows.Add(new object[] { 3, 2, 1 }); table.Rows.Add(new object[] { 4, 2, 2 });

string[] queries = new string[] { &quot;(NOT ColTwo = 1) AND (ColOne = 2)&quot;, &quot;(ColOne = 2) AND (NOT ColTwo = 1)&quot;,

&quot;NOT ColTwo = 1 AND ColOne = 2&quot;, &quot;ColOne = 2 AND NOT ColTwo = 1&quot;,

&quot;NOT ColTwo = 1 AND (ColOne = 2)&quot;, &quot;(ColOne = 2) AND NOT ColTwo = 1&quot;,

&quot;(NOT ColTwo = 1) AND ColOne = 2&quot;, &quot;ColOne = 2 AND (NOT ColTwo = 1)&quot;, };

Console.WriteLine(&quot;Select&quot;); foreach(string query in queries) { DataRow[] rows = table.Select(query); Console.WriteLine(&quot;query=\&quot;{0}\&quot; count={1}&quot;, query, rows.Length); foreach(DataRow row in rows) { Console.WriteLine(&quot;\t{0}, {1}, {2}&quot;, row[0], row[1], row[2]); } } } </li> You run the application.</li></ol>

In this scenario, you receive the following output: query=&quot;(NOT ColTwo = 1) AND (ColOne = 2)&quot; count=2 3, 2, 1       4, 2, 2 query=&quot;(ColOne = 2) AND (NOT ColTwo = 1)&quot; count=1 4, 2, 2 query=&quot;NOT ColTwo = 1 AND ColOne = 2&quot; count=1 4, 2, 2 query=&quot;ColOne = 2 AND NOT ColTwo = 1&quot; count=1 4, 2, 2 query=&quot;NOT ColTwo = 1 AND (ColOne = 2)&quot; count=2 3, 2, 1       4, 2, 2 query=&quot;(ColOne = 2) AND NOT ColTwo = 1&quot; count=1 4, 2, 2 query=&quot;(NOT ColTwo = 1) AND ColOne = 2&quot; count=1 4, 2, 2 query=&quot;ColOne = 2 AND (NOT ColTwo = 1)&quot; count=1 4, 2, 2 In this output, &quot;(ColOne = 2)&quot; is incorrectly displayed on the right side of an AND clause.

Issue 4: The internal index of a DataTable may become corrupted, and you receive a '13' error message
When you try to use the AcceptChanges method of a DataSet object that is used by the DataTable object, and you set a ForeignKey rule to AcceptRule.Cascade, the internal index values that are used by the DataSet object may become corrupted. This issue occurs if the following conditions are true:
 * The DataSet object contains one or more tables that have one-to-many relationships.
 * The AcceptChanges method of the DataSet object is called.
 * The AcceptRejectRule value of the DataSet object is set to Cascade. When this value is set to Cascade, the child table is changed so that it automatically either accepts data or rejects data.

For example, consider the following scenario:   You use the following code in the application: public void Main {           DataTable Table = new DataTable(&quot;Employee&quot;); Table.Columns.Add(&quot;Id&quot;, typeof(int)); Table.Columns.Add(&quot;ManagerId&quot;, typeof(int)); Table.Columns.Add(&quot;Name&quot;, typeof(string));

Table.Columns[&quot;Name&quot;].AllowDBNull = false; Table.PrimaryKey = new DataColumn[] {Table.Columns[&quot;Id&quot;]};

DataSet Employees = new DataSet; Employees.Tables.Add(Table);

DataRelation rel = Employees.Relations.Add(Table.Columns[&quot;ID&quot;], Table.Columns[&quot;ManagerId&quot;]); rel.ChildKeyConstraint.AcceptRejectRule = AcceptRejectRule.Cascade;

DataRow ManagerA = Table.NewRow; ManagerA[&quot;ID&quot;] = 2019; ManagerA[&quot;Name&quot;] = &quot;Manager A&quot;; Table.Rows.Add(ManagerA);

DataRow ManagerB = Table.NewRow; ManagerB[&quot;ID&quot;] = 392; ManagerB[&quot;Name&quot;] = &quot;Manager B&quot;; Table.Rows.Add(ManagerB);

DataRow EmployeeB = Table.NewRow; EmployeeB[&quot;ID&quot;] = 716; EmployeeB[&quot;Name&quot;] = &quot;Employee of B&quot;; EmployeeB.SetParentRow(ManagerB); Table.Rows.Add(EmployeeB);

EmployeeB = Table.NewRow; EmployeeB[&quot;ID&quot;] = 637; EmployeeB[&quot;Name&quot;] = &quot;2nd employee of B&quot;; EmployeeB.SetParentRow(ManagerB); Table.Rows.Add(EmployeeB);

Employees.AcceptChanges; Table.Rows.Find(392).Delete; Employees.AcceptChanges; } </li> You run the application.</li></ol>

In this scenario, you receive the following error message:

DataTable internal index is corrupted: '13'.

Issue 5: When a Merge operation occurs, the record manager may become corrupted if the target row is in the edit state
If one or more rows in a DataTable object are being edited, and then a DataTable.Merge operation occurs or a DataSet.Merge operation occurs, the record manager for the DataSet object of the DataTable object may become corrupted.

Note When a row in a DataTable object is being edited, the DataRowVersion value of the row is set to Proposed.

For example, consider the following scenario:   You use the following code in the application: using System; using System.Data; using System.Collections.Generic; using System.Text;

namespace ConsoleApplication1 {   class Program {       static void Main(string[] args) {           DataSet set = new DataSet; DataTable table = set.Tables.Add(&quot;table&quot;); table.Columns.Add(&quot;C1&quot;, typeof(int)); table.Columns.Add(&quot;C2&quot;, typeof(char)); table.PrimaryKey = new DataColumn[] { table.Columns[0] }; for (int i = 0; i < 26; ++i) {               table.Rows.Add(new object[] { i, (char)((ushort)'a' + i) }); }           table.AcceptChanges;

DataSet clone = set.Copy; clone.Tables[0].Rows[0][1] = 'Z'; //clone.AcceptChanges;

table.Rows[0][1] = '1'; table.Rows[0].BeginEdit; table.Rows[0][1] = '2';

try {               set.Merge(clone); }           finally {              foreach (DataRow row in table.Rows) { Console.WriteLine(&quot;{0}={1}&quot;, row[0], row[1]); }           }

}   } } </li> You run the application.</li></ol>

In this scenario, the record manager for the DataSet object of the DataTable object is corrupted.

To work around this problem, make sure that there are no rows in the destination DataSet object that have the DataRowVersion value set to Proposed before you use the DataTable.Merge method or the DataSet.Merge method.

Issue 6: The internal index of a DataTable object may become corrupted, and you receive a '5' error message
The following scenarios cause corruption in a DataTable object by changing the data in the DataTable object without updating the internal indexes of the DataTable object:
 * 1) The DataColumn.Expression value is changed from an expression to no expression. In this scenario, all the data in the DataColumn object is set to DBNull.
 * 2) When the DataTable.Clear method is called, all the data in the DataTable object is removed and the indexes are updated. However, other tables that reference the DataTable object are not updated.

For example, consider the following scenario:   You use the following code in the application: using System; using System.Data; using System.Collections.Generic; using System.Text;

namespace ConsoleApplication1 {   class Program {       static void Main(string[] args) {           DataSet set = new DataSet(&quot;s&quot;); DataTable table1 = set.Tables.Add(&quot;a&quot;); table1.Columns.Add(&quot;C1&quot;, typeof(int)); table1.Columns.Add(&quot;C2&quot;, typeof(int)); table1.DefaultView.Sort = &quot;C2&quot;;

DataTable table2 = set.Tables.Add(&quot;b&quot;); table2.Columns.Add(&quot;C1&quot;, typeof(int)); table2.Columns.Add(&quot;C2&quot;, typeof(int)); table2.DefaultView.Sort = &quot;C2&quot;;

set.Relations.Add(new DataRelation(&quot;t1t2&quot;, table1.Columns[0], table2.Columns[0], false)); table1.Columns[1].Expression = &quot;Sum(Child(t1t2).C2)&quot;;

AddData(table1, 1); AddData(table2, 2);

table1.Columns[1].Expression = null;

AddData(table2, 2); AddData(table1, 2);

}       private static void AddData(DataTable table, int y)        { object[] x = new object[y]; Random rand = new Random(20070125); for (int i = 0; i < 1000; ++i) {               switch (rand.Next(3)) {                   case 0: case 1: for (int k = 0; k < x.Length; ++k) {                           x[k] = rand.Next(500); }                       table.Rows.Add(x); break; case 2: if (0 < table.Rows.Count) {                           table.Rows.RemoveAt(rand.Next(table.Rows.Count)); }                       break; }           }        }

} } </li> You run the application.</li></ol>

In this scenario, you receive the following error message:

DataTable internal index is corrupted: '5'.

For more information, 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

Keywords: kbbug kbfix kbqfe kbprb kbpubtypekc kbexpertiseinter kbexpertisebeginner kbhotfixserver KB932491

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.