StackOverFlow Exception while trying to update the dataset back to the database.

  • Thread starter Thread starter Babu Mannaravalappil
  • Start date Start date
B

Babu Mannaravalappil

Can somebody please help me figure out why the following method
exceptions out?
Execution at the line marked with ********** hangs for about 15
seconds and then I get an error that says an Unhandled
StackOverFlowException occurred. The execution does not even get
passed to the catch block. At the time of my test, only one of 12
tables in the dataset (catalogsDS) really has changes. The dataset is
not a huge one. Most tables have less than 15 rows and 5 to 10
columns each.

Here is my Dev environment, just in case.
XP Pro (including all the latest patches) on P4 with 1GB RAM
VS.NET 2003 Ent. Arch. with .NET 1.1
Sql Server 2000 Local database.

private void btnUpdateDatabase_Click(object sender, System.EventArgs
e)
{
try
{
if (catalogsDS.HasChanges())
{
DataSet xDs;
xDs = catalogsDS.GetChanges(); //**********
if (!xDs.HasErrors)
{
da = DataAdapters.CatalogsAdapter();
da.Update(xDs);
UpdateStatusBar("The database has been successfully updated!");
}
}
}
catch (System.StackOverflowException st)
{
MessageBox.Show(st.Message + "\n" + st.StackTrace);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
}
}
 
Babu Mannaravalappil said:
Can somebody please help me figure out why the following method
exceptions out?
Execution at the line marked with ********** hangs for about 15
seconds and then I get an error that says an Unhandled
StackOverFlowException occurred. The execution does not even get
passed to the catch block. At the time of my test, only one of 12
tables in the dataset (catalogsDS) really has changes. The dataset is
not a huge one. Most tables have less than 15 rows and 5 to 10
columns each.

Do you have a short but complete example which demonstrates the
problem?
 
I am afraid I don't have a short version of the code. I may have to do a
lot of work to make it short enough but still a working module. The whole
flow is tied up with a user interface with a few tabbed pages. All the
pages interact with each other based on the current node on a tree.
Something like Windows explorer. But the right hand pane has a few tabbed
pages. Nothing fancy. All the controls are normal controls like text boxes
and combo boxes. The underlying dataset is a typed dataset that was created
through the dataset schema designer and each table filled by
SqlDataAdapters.

Does that help?

Babu.
 
Babu Mannaravalappil said:
I am afraid I don't have a short version of the code. I may have to do a
lot of work to make it short enough but still a working module. The whole
flow is tied up with a user interface with a few tabbed pages.

You shouldn't need any GUI at all, unless you've got GUI events tied up
in the code which is executed at that point.
All the
pages interact with each other based on the current node on a tree.
Something like Windows explorer. But the right hand pane has a few tabbed
pages. Nothing fancy. All the controls are normal controls like text boxes
and combo boxes. The underlying dataset is a typed dataset that was created
through the dataset schema designer and each table filled by
SqlDataAdapters.

Does that help?

I suspect it's nothing to do with the controls - I would imagine it's
something like an OnRowChanged (or whatever) event handler which is
calling itself.
 
I just found out that if I do the database update one table at time rather
than the whole dataset, in other words, instead of calling like
dataadapter.update(dataset), if I call like
dataadapter.update(dataset.table1);
dataadapter.update(dataset.table2);....etc., it seems to work fine. No more
stack overflow. But I was trying to avoid calling update methods
separately. I assume separate calls to update each table makes those many
trips to the database server. Whereas (this is just my assumption), if I
call the update on the dataset on the whole, it only makes one trip to the
database. Am I assuming correctly?

Babu.
 
Babu Mannaravalappil said:
I just found out that if I do the database update one table at time rather
than the whole dataset, in other words, instead of calling like
dataadapter.update(dataset), if I call like
dataadapter.update(dataset.table1);
dataadapter.update(dataset.table2);....etc., it seems to work fine. No more
stack overflow. But I was trying to avoid calling update methods
separately. I assume separate calls to update each table makes those many
trips to the database server. Whereas (this is just my assumption), if I
call the update on the dataset on the whole, it only makes one trip to the
database. Am I assuming correctly?

No - there's no particular difference between updating a dataset as a
whole and updating each table individually, as far as the database
connection is concerned. Bear in mind that the data adapter doesn't put
everything into a single transaction or anything like that - it just
goes through each changed row and executes the appropriate command.

However, I would look closely at what's happening to give you the
difference in behaviour here...
 
Thanks Jon.

Babu.

Jon Skeet said:
No - there's no particular difference between updating a dataset as a
whole and updating each table individually, as far as the database
connection is concerned. Bear in mind that the data adapter doesn't put
everything into a single transaction or anything like that - it just
goes through each changed row and executes the appropriate command.

However, I would look closely at what's happening to give you the
difference in behaviour here...
 
Back
Top