Transaction object question

R

REB

If I create a transaction object for rolling back a insert query in the on
click event of a form button can the transaction be tracked across other
functions?

For example:

private void btnSaveDriver_Click(object sender, System.EventArgs e)

{

Create transaction object

Execute a insert query into a primary table

Call_Funtion_One(int primary_key_from_intial_insert)

Call_Funtion_Two(int Primarykey)

on error rollback everything exectued above

}

Call_Funtion_One(int Primarykey)

{

Execute query to insert data in a related table using key passed into the
function

}

Call_Funtion_Two(int Primarykey)

{

Execute query to insert data in a related table using key passed into the
function

}

I hope what I am asking makes sense, if not please let me know and I will
try to elaborate further.
 
H

Harsh Thakur

Hi,

To track the transaction, you will need to pass a
reference to the transaction object to the functions you
call.

A better way to do it might be like this:

try{
create connection
create transaction

call func1() //performs inserts/updates
call func2() //performs inserts/updates
...
}catch(Exception x){
transaction.Rollback()
}
transaction.Commit()

OR
you could inherit your business classes from
ServicedComponent and use the COM+ features for
transaction management.

HTH
Regards
Harsh Thakur
 

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