You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Gilles Bayon <ib...@gmail.com> on 2005/08/26 07:59:58 UTC
Re: Nested OpenConnection() BeginTransaction()
BeginTransaction : Open a conenction & begin a transaction so all is normal
On 8/25/05, David Marzo (Puzzlet) <da...@puzzlet.net> wrote:
>
>
> I Have this scenarios that works ok:
>
> daoManager.BeginTransaction();
> daoManager.CommitTransaction();
>
> daoManager.BeginTransaction();
> daoManager.RollBackTransaction();
>
> daoManager.OpenConnection();
> daoManager.CloseConnection();
>
> But this fail
>
> 1) daoManager.OpenConnection();
> 2) daoManager.BeginTransaction();
> 3) daoManager.CommitTransaction(false);
> 4) daoManager.CloseConnection();
>
> With this Exception
>
> IBatisNet.DataAccess.Exceptions.DataAccessException : DaoManager could
> not invoke BeginTransaction(). A DaoSession is already started. Call
> CommitTransaction() or RollbackTransaction first.
>
> In line 2
>
> I check the source code and I found in IBatisNet.DataMapper.SqlMapper
>
> /// <summary>
> /// Begins a database transaction.
> /// </summary>
> public IDalSession BeginTransaction()
> {
> if (_sessionHolder.LocalSession != null)
> {
> throw new DataMapperException(
> "SqlMap could not invoke BeginTransaction(). A Transaction is
> already started. Call CommitTransaction() or
> RollbackTransaction
> first.");
> }
> //...///
>
> Is a bug, test for session instead for open transaction, or I missing
> some piece of the puzzle.
>
> In ADO.NET <http://ADO.NET> this scenario works
>
> IdbConnection connection = <new connection>;
> connection.Open()
> IdbCommand cmdA = connection.CreateCommand();
> <execute cmdA>
> IdbTransaction transaction = connection.BeginConnection();
> IdbCommand cmdB = transaction.Connection.CreateCommand();
> <execute cmdB>
> transaction.Commint()
> connection.Close();
>
>
> Thanks in advance
>
> Un saludo:
>
> David Marzo
>
>
>
>
>
>
RE: RE: Nested OpenConnection() BeginTransaction()
Posted by "David Marzo (Puzzlet)" <da...@puzzlet.net>.
I Resolve my problem access direct to LocalSession of daoManager
daoManager.OpenConnection();
daoManager.LocalDaoSession.BeginTransaction(false);
daoManager.LocalDaoSession.CommitTransaction(false);
daoManager.CloseConnection();
But also I think the this use should be correct:
1) daoManager.OpenConnection ();
2) daoManager.BeginTransaction();
3) daoManager.CommitTransaction(false);
4) daoManager.CloseConnection();
Why this Exception is throw?:
IBatisNet.DataAccess.Exceptions.DataAccessException : DaoManager could
not invoke BeginTransaction(). A DaoSession is already started. Call
CommitTransaction() or RollbackTransaction first.
Un saludo:
David Marzo