BeginTransaction helppppppppppppppppppp?

P

perspolis

Hi all
I have two class one master and another detail that connect to sql server
database.
and every class has a method name "BeginSave" that starts a transaction and
"EndSave" method to commit transaction.
when I want to save changes I call these two methods
master.BeginSave();
detial.BeginSave();
detail.EndSave();
master.EndSave();
but it dosen't work and gives me "timeout connection error".
I wanted to know dose .Net support nested transaction??
then how can I solve this problem???
thanks in advance
 
F

Frans Bouma [C# MVP]

perspolis said:
Hi all
I have two class one master and another detail that connect to sql
server database.
and every class has a method name "BeginSave" that starts a
transaction and "EndSave" method to commit transaction.
when I want to save changes I call these two methods
master.BeginSave();
detial.BeginSave();
detail.EndSave();
master.EndSave();
but it dosen't work and gives me "timeout connection error".
I wanted to know dose .Net support nested transaction??
then how can I solve this problem???
thanks in advance

Nested transactions aren't supported, as Sqlserver doesn't support
nested transactions. Your timeout occurs because you touch rows during
saving of the detail which are locked by the master.

You should implement it differently: create a separate transaction
class, which contains the connection and the Sqltransaction object. You
then 'add' your master and detail to that object and call their save
methods. These save methods then should check if the object is added to
a transaction object, and if so it should use the connection of that
transaction object.

After all save actions, you simply call commit on the transaction
object, which calls the SqlTransaction.Commit() (or Rollback in case of
an exception) routine.

Frans

--
 
P

perspolis

thx Frans :)
Frans Bouma said:
Nested transactions aren't supported, as Sqlserver doesn't support
nested transactions. Your timeout occurs because you touch rows during
saving of the detail which are locked by the master.

You should implement it differently: create a separate transaction
class, which contains the connection and the Sqltransaction object. You
then 'add' your master and detail to that object and call their save
methods. These save methods then should check if the object is added to
a transaction object, and if so it should use the connection of that
transaction object.

After all save actions, you simply call commit on the transaction
object, which calls the SqlTransaction.Commit() (or Rollback in case of
an exception) routine.

Frans

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top