EO.Save DataTable already belongs to another DataSet

Data Access Application Blocks Forum

EO.Save DataTable already belongs to another DataSet

Postby daveyjclark on Thu Jan 26, 2006 11:45 am

Hi Matt,
First of all, great product, saved me hours (probably weeks) of work.

I have a couple of grids bound to eo's, the tables have unique keys on them on two columns.
When i violate these keys, the save method obviously raises an exception.
I trap this SQL exception and issue a warning to the user that they are a muppet, because they have entered duplicate data.
This may seem lazy, i should probably check for duplicates before saving, but anyhoo, here is the problem....

When the user subsequently changes the data to correct values, the next save raises \"DataTable already belongs to another DataSet\".
This is because you cannot have the same datatable in different datasets.

I changed the eo.save method to clear the dataset in the finally clause, as below and all now works fine, what are your thoughts on this ?

public virtual void Save()
{
if (_dataTable == null) { return; }

TransactionManager txMgr = TransactionManager.ThreadTransactionMgr();
DataSet ds = new DataSet();
try
{
..................

// Clean up resources
txMgr.CommitTransaction();

}

catch (Exception ex)
{
if (!(txMgr == null))
{
txMgr.RollbackTransaction();
txMgr.TransactionCommitted -= new TransactionManager.TransactionCommittedDelegate(this.txMgr_TransactionCommitted);
}
throw ex;
}
finally
{
ds.Tables.Clear();
}


Once again, thanks for all your efforts

Dave
daveyjclark
Lurker
 
Posts: 9
Joined: Thu Jan 26, 2006 11:16 am

Postby mgnoonan on Thu Jan 26, 2006 1:11 pm

Congratulations. You may have found the first verifiable bug in EasyObjects! 8)

That change makes perfect sense, I'm surprised no one else has seen it before (including yours truly!). I will incorporate this into the 1.1 release.

I think the reason I haven't run into it myself is that I do more web apps than Windows apps, where the objects are destroyed and recreated on every postback.

Great catch. Thanks!
Matt Noonan
EasyObjects.NET - The O/RM for the Enterprise Library
http://www.easyobjects.net
User avatar
mgnoonan
Expert
 
Posts: 1019
Joined: Tue Sep 14, 2004 3:17 am
Location: Springboro, OH


Return to EasyObjects.NET (Microsoft Enterprise Library)

Who is online

Users browsing this forum: No registered users and 1 guest

cron