M
Marina
I have some code that runs some updates/inserts inside a transaction. I
have logged the following message in my error log:
This SqlTransaction has completed; it is no longer usable. at
System.Data.SqlClient.SqlTransaction.Rollback()
The line number points to the 'trans.Rollback();' line.
So what this is saying - is that the transaction was committed - and then
there was an attempt to roll it back. However, as you see , trans.Commit is
the last line of code in the try block. So there is nothing else to have
caused an error. So it must have something in the Commit?
All the updates/inserts went through successfully, however. Even the message
says that the transaction has completed. So if the transaction was
committed - why was there an error that caused the catch to execute?
I haven't been able to reproduce this - but it happening once is a concern.
Can anyone shed light on this?
The code is below...
try{
conn.Open();
trans = conn.BeginTransaction();
command.Transaction = trans;
command.ExecuteNonQuery();
trans.Commit();
}
catch(Exception ex)
{
if (trans != null)
trans.Rollback();
}
finally
{
conn.Close();
}
have logged the following message in my error log:
This SqlTransaction has completed; it is no longer usable. at
System.Data.SqlClient.SqlTransaction.Rollback()
The line number points to the 'trans.Rollback();' line.
So what this is saying - is that the transaction was committed - and then
there was an attempt to roll it back. However, as you see , trans.Commit is
the last line of code in the try block. So there is nothing else to have
caused an error. So it must have something in the Commit?
All the updates/inserts went through successfully, however. Even the message
says that the transaction has completed. So if the transaction was
committed - why was there an error that caused the catch to execute?
I haven't been able to reproduce this - but it happening once is a concern.
Can anyone shed light on this?
The code is below...
try{
conn.Open();
trans = conn.BeginTransaction();
command.Transaction = trans;
command.ExecuteNonQuery();
trans.Commit();
}
catch(Exception ex)
{
if (trans != null)
trans.Rollback();
}
finally
{
conn.Close();
}