Use transactions
The isolation level can be modified at any time and valid before the display changes. If the isolation level is modified during a transaction, the server should apply a new blocking level to all the remaining statements.
Terminate a transaction explicitly by using the commit or rollback method.
Transaction recovery transactionscope object
Implement Distributed Transaction Processing
Bool Cancommit = True ;
Using (Transactionscope TS = New System. Transactions. transactionscope ())
{
// **************************************** *****************
// Update northwind on SQL Server 2000
Using (Sqlconnection Conn = New Sqlconnection (connstring ))
{
Sqlcommand cmd = New Sqlcommand (updatecmd, Conn );
Cmd. Connection. open ();
Try
{
Cmd. executenonquery ();
}
Catch (Sqlexception ex)
{
// Error Handling Code goes here
Lblmessage. Text + = Ex. message;
Cancommit & = False ;
}
}
// **************************************** *****************
// Update numbers on SQL Server 2005
Using (Sqlconnection Conn = New Sqlconnection (connstring05 ))
{
// Sqlcommand cmd = new sqlcommand (raiseerror, Conn );
Sqlcommand cmd = New Sqlcommand (insertcmd, Conn );
Cmd. Connection. open ();
Try
{
Cmd. executenonquery ();
}
Catch (Sqlexception ex)
{
// Error Handling Code goes here
Lblmessage. Text + = Ex. message;
Cancommit & = False ;
}
}
// Must call to complete; otherwise abort
If (Cancommit)
TS. Complete ();
}