473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Urgent: DataTable.Clear problem..

We've suddenly started getting a problem with a call to clear the contents
of a DataTable. This is on a live customer site that's been working fine
until yesterday. As far as we know they've not changed or updated the
server in any way.

"There is no row at position 42"

at System.Data.RBTree`1.GetNodeByIndex(int32 userIndex)
at System.Data.DataTable.Clear(Boolean clearAll)
at system.Data.DataTable.Clear()

Public Overrides Sub GetTable(ByRef aTbl As DataTable, ByVal aSQL As String)
If aTbl Is Nothing Then
aTbl = New DataTable
Else
aTbl.Clear()
End If
' code to retrieve data
End Sub

Any ideas ?
--
Adrian Parker
Ingenuity At Work Ltd
Oct 18 '06 #1
4 2938
Hi Adrian,

Based on my experience, this is most likely caused by the underlying
DataTable's content is being changed by other thread while Clear() is
executing. Is it possible that other thread may be referencing the
DataTable too?

Also, in your specific scenario, wouldn't it be ok to always create a new
DataTable in your GetTable() method?

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 18 '06 #2
Seems like a multithreading problem.

What's the scope of the DataTable in question? Is it stored in the
Application? In a shared/static field? In the Session object, a local var of
the calling function? The Cache?

My guess is that it's shared accross multiple users via the Cache,
Application or a static/shared field....and you're getting 1 request
modifying the table at the same time as another one is trying to clear it.

Whenever you deal with resources across multiple threads, you need to be
careful to syncrhonize any volatile operation..

Specifically, this is code within Clear:

for (int num1 = 0; num1 < this.rowCollection.Count; num1++)
{
DataRow row1 = this.rowCollection[num1];
row1.oldRecord = -1;
row1.newRecord = -1;
//do more stuff with row1
}
if this.rowCollection.Count returns 100....
it starts to loop..by the time it reachs the 99, another thread might have
deleted row 99, and then you're in the mess you're in :)

Simply placing locks around the volatile code is the simplest solution,
though I would recommend a more thorough examination..

karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Adrian Parker" <ap******@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
We've suddenly started getting a problem with a call to clear the contents
of a DataTable. This is on a live customer site that's been working fine
until yesterday. As far as we know they've not changed or updated the
server in any way.

"There is no row at position 42"

at System.Data.RBTree`1.GetNodeByIndex(int32 userIndex)
at System.Data.DataTable.Clear(Boolean clearAll)
at system.Data.DataTable.Clear()

Public Overrides Sub GetTable(ByRef aTbl As DataTable, ByVal aSQL As
String)
If aTbl Is Nothing Then
aTbl = New DataTable
Else
aTbl.Clear()
End If
' code to retrieve data
End Sub

Any ideas ?
--
Adrian Parker
Ingenuity At Work Ltd


Oct 18 '06 #3
Aha, code has the datatable varaible created as Public Shared for some
reason.

Thanks for hte hint :)

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:%2****************@TK2MSFTNGP05.phx.gbl...
| Seems like a multithreading problem.
|
| What's the scope of the DataTable in question? Is it stored in the
| Application? In a shared/static field? In the Session object, a local var
of
| the calling function? The Cache?
|
| My guess is that it's shared accross multiple users via the Cache,
| Application or a static/shared field....and you're getting 1 request
| modifying the table at the same time as another one is trying to clear it.
|
| Whenever you deal with resources across multiple threads, you need to be
| careful to syncrhonize any volatile operation..
|
| Specifically, this is code within Clear:
|
| for (int num1 = 0; num1 < this.rowCollection.Count; num1++)
| {
| DataRow row1 = this.rowCollection[num1];
| row1.oldRecord = -1;
| row1.newRecord = -1;
| //do more stuff with row1
| }
|
|
| if this.rowCollection.Count returns 100....
| it starts to loop..by the time it reachs the 99, another thread might have
| deleted row 99, and then you're in the mess you're in :)
|
| Simply placing locks around the volatile code is the simplest solution,
| though I would recommend a more thorough examination..
|
| karl
|
| --
| http://www.openmymind.net/
| http://www.fuelindustries.com/
|
|
| "Adrian Parker" <ap******@nospam.nospamwrote in message
| news:%2****************@TK2MSFTNGP05.phx.gbl...
| We've suddenly started getting a problem with a call to clear the
contents
| of a DataTable. This is on a live customer site that's been working
fine
| until yesterday. As far as we know they've not changed or updated the
| server in any way.
| >
| "There is no row at position 42"
| >
| at System.Data.RBTree`1.GetNodeByIndex(int32 userIndex)
| at System.Data.DataTable.Clear(Boolean clearAll)
| at system.Data.DataTable.Clear()
| >
| Public Overrides Sub GetTable(ByRef aTbl As DataTable, ByVal aSQL As
| String)
| If aTbl Is Nothing Then
| aTbl = New DataTable
| Else
| aTbl.Clear()
| End If
| ' code to retrieve data
| End Sub
| >
| >
| >
| Any ideas ?
| --
| Adrian Parker
| Ingenuity At Work Ltd
| >
| >
|
|
Oct 18 '06 #4
Just make sure there wasnt' a good reason for it to be shared...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Adrian Parker" <ap******@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Aha, code has the datatable varaible created as Public Shared for some
reason.

Thanks for hte hint :)

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:%2****************@TK2MSFTNGP05.phx.gbl...
| Seems like a multithreading problem.
|
| What's the scope of the DataTable in question? Is it stored in the
| Application? In a shared/static field? In the Session object, a local
var
of
| the calling function? The Cache?
|
| My guess is that it's shared accross multiple users via the Cache,
| Application or a static/shared field....and you're getting 1 request
| modifying the table at the same time as another one is trying to clear
it.
|
| Whenever you deal with resources across multiple threads, you need to be
| careful to syncrhonize any volatile operation..
|
| Specifically, this is code within Clear:
|
| for (int num1 = 0; num1 < this.rowCollection.Count; num1++)
| {
| DataRow row1 = this.rowCollection[num1];
| row1.oldRecord = -1;
| row1.newRecord = -1;
| //do more stuff with row1
| }
|
|
| if this.rowCollection.Count returns 100....
| it starts to loop..by the time it reachs the 99, another thread might
have
| deleted row 99, and then you're in the mess you're in :)
|
| Simply placing locks around the volatile code is the simplest solution,
| though I would recommend a more thorough examination..
|
| karl
|
| --
| http://www.openmymind.net/
| http://www.fuelindustries.com/
|
|
| "Adrian Parker" <ap******@nospam.nospamwrote in message
| news:%2****************@TK2MSFTNGP05.phx.gbl...
| We've suddenly started getting a problem with a call to clear the
contents
| of a DataTable. This is on a live customer site that's been working
fine
| until yesterday. As far as we know they've not changed or updated the
| server in any way.
| >
| "There is no row at position 42"
| >
| at System.Data.RBTree`1.GetNodeByIndex(int32 userIndex)
| at System.Data.DataTable.Clear(Boolean clearAll)
| at system.Data.DataTable.Clear()
| >
| Public Overrides Sub GetTable(ByRef aTbl As DataTable, ByVal aSQL As
| String)
| If aTbl Is Nothing Then
| aTbl = New DataTable
| Else
| aTbl.Clear()
| End If
| ' code to retrieve data
| End Sub
| >
| >
| >
| Any ideas ?
| --
| Adrian Parker
| Ingenuity At Work Ltd
| >
| >
|
|


Oct 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ubi | last post by:
hi i have a problem with System.Data.DataViewRowState. i have a ReadOnly datagrid, a dataView and a dataTable. i'm using the dataView's filter property to filter the data (firstName =...
1
by: Daniel | last post by:
Hi, i create datatable using code and add some columns in it.. the problems happen sometimes i load the datatable for the lst time, the error happens at createing the column: the error message...
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
1
by: Simon | last post by:
Hi All, I have a DataGrid bound to a DataTable. Every once in a while I need to refresh the data in the table so that the updated data is displayed in the DataGrid. Here's how I am attempting...
4
by: Brett Romero | last post by:
I fill a DataTable with search results, which take a very long time if I first clear it. The values come from an object and I map them into the corresponding table columns. I may have 65000...
0
by: nil | last post by:
Help me.i am new to vb.net and i am developing one web application in vb.net2003. I am facing many problems in that so i would like to tell you one of them. I hope i will have the good response...
8
by: cj | last post by:
I have a program to display queries to a SQL db. I type my query in a textbox and click a button and the results display in a datagrid. I could use either dataset or datatable to read the data in...
0
by: XenReborn | last post by:
Ok this should be simple. I made a form, added a combobox (for selecting items to edit, not for updating fields), several textboxes, a few checkboxes etc. On formshow it connects to my database,...
9
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.