(O)enone
2007-10-31 15:10:34 UTC
I am experiencing a problem with transaction handling in my SQL Server-based
application. To demonstrate the problem, here are some simple T-SQL
statements, which can be executed one by one in SQL Server Management
Studio:
\\\
-- Get the current transaction count, which is of courser zero
select @@trancount
-- Begin a transaction named "Test"
begin transaction Test
-- Get the transaction count -- this time it's 1, as expected
select @@trancount
-- Perform a SELECT statement that fails. This returns an error because it
can't cast 'Hello' as an integer.
select 'Hello'+1
-- Get the transaction count for a file time. This now returns zero.
select @@trancount
///
The SELECT statement is causing SQL Server to automatically roll back the
transaction. This is causing problems in my application, as the program
doesn't expect the transaction to have rolled back at this point. Upon
handling this error, the program then attempts to explicitly roll back the
transaction, which causes SQL Server to error for a second time, stating
that the ROLLBACK has no corresponding BEGIN TRANSACTION. I therefore lose
sight of the original error that actually occurred.
Is there a way to stop SQL Server from automatically rolling back
transactions? I really want the only thing that causes the transaction to
roll back to be an explicit ROLLBACK command.
I've tried SET ARITHABORT OFF and SET XACT_ABORT OFF, but neither made any
difference to the results of the steps above.
Can anyone enlighten me as to how I can get this to do what I want?
(Running against SQL Server 2000, but the same results are experienced in
SQL Server 2005).
Many thanks,
application. To demonstrate the problem, here are some simple T-SQL
statements, which can be executed one by one in SQL Server Management
Studio:
\\\
-- Get the current transaction count, which is of courser zero
select @@trancount
-- Begin a transaction named "Test"
begin transaction Test
-- Get the transaction count -- this time it's 1, as expected
select @@trancount
-- Perform a SELECT statement that fails. This returns an error because it
can't cast 'Hello' as an integer.
select 'Hello'+1
-- Get the transaction count for a file time. This now returns zero.
select @@trancount
///
The SELECT statement is causing SQL Server to automatically roll back the
transaction. This is causing problems in my application, as the program
doesn't expect the transaction to have rolled back at this point. Upon
handling this error, the program then attempts to explicitly roll back the
transaction, which causes SQL Server to error for a second time, stating
that the ROLLBACK has no corresponding BEGIN TRANSACTION. I therefore lose
sight of the original error that actually occurred.
Is there a way to stop SQL Server from automatically rolling back
transactions? I really want the only thing that causes the transaction to
roll back to be an explicit ROLLBACK command.
I've tried SET ARITHABORT OFF and SET XACT_ABORT OFF, but neither made any
difference to the results of the steps above.
Can anyone enlighten me as to how I can get this to do what I want?
(Running against SQL Server 2000, but the same results are experienced in
SQL Server 2005).
Many thanks,
--
(O)enone
(O)enone