ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Sorensen" <bsoren...@idtdna.com>
Subject Starting transaction after open connection
Date Thu, 21 Dec 2006 21:13:39 GMT
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

Mime
View raw message