Have Adapter Use Existing Transaction?

Posts   
 
    
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 04-Apr-2007 21:52:21   

Hello,

I have a situation where I need to do some updates to the database using the adapter using a transaction that was started via a vanilla ADO.Net call.

Is this code correct (added to derived DataAccessAdapter):


        private System.Data.IDbTransaction _transaction = null;

        public System.Data.IDbTransaction DatabaseTransaction
        {
            get { return _transaction; }
            set { value = _transaction; }
        }
        
        protected override System.Data.IDbTransaction CreateNewPhysicalTransaction()
        {
            if (DatabaseTransaction == null)
            {
                return base.CreateNewPhysicalTransaction();
            }
            else
            {
                return _transaction;
            }
        }

Do I need to do this for DBConnection as well?

Also, if I wanted to do the reverse, make an ADO.Net call using a transaction started by the adapter, how would I go about it?

Thanks,

Phil

(Edit: version 2.0, latest version of everything, adapter vs. SQL 2005)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Apr-2007 11:30:47   

I think the following thread might answer your question: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4670

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 05-Apr-2007 15:48:40   

Walaa wrote:

I think the following thread might answer your question: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4670

Yep, I saw this thread, and this is what I based my code on. I just wanted to verify that I was doing it correctly, since the only public methods in the code in that thread involve closing the connection.

Also, I can't find anything about sharing a connection/transaction created by the adapter with an external database call. Is there a way to get the connection/transaction FROM the adapter?

Thanks,

Phil

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Apr-2007 16:27:23   
Is there a way to get the connection/transaction FROM the adapter?

**PhysicalTransaction **property GetActiveConnection() method

Please refer to the LLBLGen Pro reference manual