Seems to be a bug, to avoid it don't use using and do it as

sqlMap.OpenConnection();

    sqlMap.BeginTransaction(false);
    // do stuff
    sqlMap.CommitTransaction(false);

sqlMap.CloseConnection();

On 12/21/06, Bill Sorensen <[EMAIL PROTECTED]> wrote:

I'm running into problems with disposing of a session.  I'd like to keep
a connection open for an extended period, and occasionally run
transactions in it.  If I write my code as follows:

using (IDalSession session = Mapper.Instance().OpenConnection())
{
       Mapper.Instance().LocalSession.BeginTransaction(false);
       // do stuff
       Mapper.Instance().LocalSession.CommitTransaction(false);
}

The code blows up when the using block ends:

System.InvalidOperationException: This SqlTransaction has completed; it
is no longer usable.
  at System.Data.SqlClient.SqlTransaction.ZombieCheck()
  at System.Data.SqlClient.SqlTransaction.Rollback()
  at IBatisNet.DataMapper.SqlMapSession.RollBackTransaction()
  at IBatisNet.DataMapper.SqlMapper.RollBackTransaction()
  at IBatisNet.DataMapper.SqlMapSession.Dispose()

This is a simplified example - the final code would have try..catch and
multiple transactions over time (not nested).

My workaround is to call OpenConnection() and CloseConnection()
explicitly, and avoid the using block.

Is this a bug, or am I doing something wrong?

Thanks!
Bill Sorensen
Integrated DNA Technologies




--
Cheers,
Gilles

<a href="http://www.amazon.com/gp/registry/6JCP7AORB0LE";>Wish List</a>

Reply via email to