Transactions in .Net
Reply
![]() |
|
From:
![]() sistlavenkat
|
Sushil,
SQL Server 2000 enlists a DML statement such as insert in a trasaction when you use "SET ANSI_DEFAULTS ON" option in your strored procedure. It would be using implicit transactions in this case.
Howsoever, if you have to commit, then you have to explicitly state COMMIT TRAN for both implicit and explicit transactions.
If you want to leverage SQL Transaction provided by ADO.NET, then you can do something like this.
// Declare transaction object private SQLTransaction Trans;
//Begin Transaction private SqlTransaction BeginTran() { try { this.trans = connection.BeginTransaction(); return (this.trans); } catch (Exception ex) { . your exception here } } //on similar lines you can write for commit, rollback transaction.
// finally in your insert method try { <yourinsert.beginTrans> // your SQL insert code block goes here <yourinsert.endTrans> } catch { //do not forget to rollback if error occurs <yourinsert.RollbackTrans> }
Finally, you have to ensure that, you will use the same transaction object that was declared in begin trans.
HTH, venkat.Murthy private SqlTransaction EndTran() { try { this.transaction = connection.BeginTransaction(); return (this.transaction); } catch (Exception ex) { .. your exception here } } |
|
View other groups in this category.
![]() |
To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.
Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.
If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.
|
|
- Re: Transactions in .Net dotNET User Group Hyd
-