Monday, March 19, 2012

How to rollback a transaction in Data Access Layer

Hi,

I am having a application in which from the front end i am saving details of three different things

i.Enquiry Details

ii.Parts Details

iii.Machine details

i am saving the Enquiry detail in a data table,Parts Details in a data table and machine detail in a data table and finally i am adding the three data tables into a single data set and passing the data set to data access layer there i have three insert command one for each data table in my case the enquiry data table will be saved first and then the next two details will be saved and i am saving the details in three different tables in the database, my problem is some times the enquiry details will save to the database and while saving the Parts details there may be some exception and i will throw an exception in that case the enquiry details will be saved and the remaining two details are not saved(Which are also part of the same Transaction).I wanted to know about how to call the transaction function in case of Data Access Layer.

Do you want to store the data independtly. Even the tail 2 tables failed you want to successfully commit the first insert?

Pls explain the last statement?

|||

You can use a user transaction which can be opend through Sqlconnection.begintransaction()

See the MSDN for more details:

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.begintransaction.aspx

The transaction is tied to the connection but can be commited separately.

Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Thanks for Reply,

The answers for your questions are below

1.Do you want to store the data independtly?

yes i am storing the data in three different tables.

2.Even the tail 2 tables failed you want to successfully commit the first insert?

No i want to roll back the entire transaction.

No comments:

Post a Comment