G
Guest
Running SQL Server 2000 SP4
and .NET Framework 1.1.43322 SP1
I have a trigger that does some work and then, when it decides there is a
problem does:
if @ErrMsg is not null
BEGIN
RAISERROR (50001,16,1, 'AssetConfig', 'AssetKey/Site', @ErrMsg)
ROLLBACK transaction
In my Windows Forms application I have
try
{
SqlTransaction sqlTrans = ….BeginTransaction();
Update several tables, including the one with the trigger
sqlTrans.Commit();
}
catch (SqlException e)
{
sqlTrans.Rollback();
}
When the trigger raises the error, I do not get the @ErrMsg because the
SqlDataAdapter does not trap the error. Instead, I get
System.InvalidOperationException: This SqlTransaction has completed; it is
no longer usable.
at System.Data.SqlClient.SqlTransaction.Rollback()
at the Rollback statement.
This is because the Commit threw this SqlException
Message # 3902 "The COMMIT TRANSACTION request has no corresponding
BEGIN TRANSACTION."
What I WANT is to have the SqlDataAdapter.Update throw the error that I have
specified, just as it would do if, for example, a primary or foreign key had
been violated. Then the catch block would do the rollback and handle the
error. I tried taking the Rollback out of the trigger, but then I got no
message, no error, and the database was updated with bad data. What is the
secret to making SQL Server Raiserror work with the Framework to return a
meaningful error?
and .NET Framework 1.1.43322 SP1
I have a trigger that does some work and then, when it decides there is a
problem does:
if @ErrMsg is not null
BEGIN
RAISERROR (50001,16,1, 'AssetConfig', 'AssetKey/Site', @ErrMsg)
ROLLBACK transaction
In my Windows Forms application I have
try
{
SqlTransaction sqlTrans = ….BeginTransaction();
Update several tables, including the one with the trigger
sqlTrans.Commit();
}
catch (SqlException e)
{
sqlTrans.Rollback();
}
When the trigger raises the error, I do not get the @ErrMsg because the
SqlDataAdapter does not trap the error. Instead, I get
System.InvalidOperationException: This SqlTransaction has completed; it is
no longer usable.
at System.Data.SqlClient.SqlTransaction.Rollback()
at the Rollback statement.
This is because the Commit threw this SqlException
Message # 3902 "The COMMIT TRANSACTION request has no corresponding
BEGIN TRANSACTION."
What I WANT is to have the SqlDataAdapter.Update throw the error that I have
specified, just as it would do if, for example, a primary or foreign key had
been violated. Then the catch block would do the rollback and handle the
error. I tried taking the Rollback out of the trigger, but then I got no
message, no error, and the database was updated with bad data. What is the
secret to making SQL Server Raiserror work with the Framework to return a
meaningful error?