G
Guest
I've implemented the USING statement to ensure that my newly created sql
connection closes when my method is finished using it. The USING statement is
wrapped in try/catch error handling statement. This works fine.
When i try to implement the "SqlTransation" class, the code does not work as
the SqlTransation object is out-of-scope in the catch statement, and/or,
after the USING statement ends, the sql connection object is automatically
closed ??
For example...
try
{
using (SqlConnection sqlCn = new SqlConnection())
{
// establish sqlCn params
SqlTransaction myTrans;
sqlTrans = sqlCn.BeginTransaction();
// code to execute (SqlCommands)
myTrans.Commit();
}
}
catch (SqlException ex)
{
myTrans.RollBack();
// error handling code
}
.... Is it not possible to implement both the USING statment and the
SqlTransation class at the same time?
Thanks,
connection closes when my method is finished using it. The USING statement is
wrapped in try/catch error handling statement. This works fine.
When i try to implement the "SqlTransation" class, the code does not work as
the SqlTransation object is out-of-scope in the catch statement, and/or,
after the USING statement ends, the sql connection object is automatically
closed ??
For example...
try
{
using (SqlConnection sqlCn = new SqlConnection())
{
// establish sqlCn params
SqlTransaction myTrans;
sqlTrans = sqlCn.BeginTransaction();
// code to execute (SqlCommands)
myTrans.Commit();
}
}
catch (SqlException ex)
{
myTrans.RollBack();
// error handling code
}
.... Is it not possible to implement both the USING statment and the
SqlTransation class at the same time?
Thanks,