Solved

Distributed transaction completed. Either enlist this session in a new transaction ..

Posted on 2004-03-22
9
1,118 Views
Last Modified: 2010-05-18
Hi,

I have an mts object written in vb, named A. Its transaction mode is 'required transaction' A calls an object named B with mode 'uses transaction'. B calls a data access component C which accesses the database. C also has a mode of  'uses
transaction'. The number of calls to B from A are large.

I keep getting this error, after a method in object A is called:

"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction."

I want to understand how and why this error comes up. I am not accessing distributed databases. IS this error saying that the transaction has already committed, and another database access is trying to commit the transaction again?

Do we have to encapsulate every write to the database with a
transaction, or can we combine a number of writes into one transaction, as I am doing?

Thanks!




0
Comment
Question by:reader
  • 4
  • 3
9 Comments
 
LVL 22

Expert Comment

by:Snarf0001
ID: 10648784
You can definately enlist multiple writes into the same transaction, this is the primary reason for using them.  It sounds like either A or B is committing or rolling back the transaction before the next component can use it.

Make sure you are actually calling the BeginTrans method in object A, if not an implicit transaction will be created (and committed) with every call to the db.
Also double check all of the code, and make sure you are not committing or rolling it back in A or B and then calling another component.

Lastly, ensure you are instantiating B and C with the CreateInstance method of the ObjectContext.  If created with any other method (new, CreateObject...) the objects will be created and will function normally, but will not be able to take part in the same transaction.

Hope this is of some help.
0
 

Author Comment

by:reader
ID: 10652098
How should I call the BeginTrans method in object A? Since
its transaction mode is 'required transaction', A is enlisted in an implicit transacion I believe.

My question is: should I use explicit transactions with the TransactionContextObject, since A does not have any method called BeginTrans ..? Where do i get this BeginTrans method?
0
 
LVL 22

Expert Comment

by:Snarf0001
ID: 10652318
My apologies, upon reading again my comment was horribly unclear.

The BeginTrans would be called on the database connection object, but is required for DB transaction ONLY (without MTS).  MTS does start and carry over implicit transactions itself, including calls to the database.

Object B must then be initialized as follows:

Dim ctxObject As ObjectContext
Dim objAccount As {ObjB.ProgID}

Set ctxObject = GetObjectContext()

Set objAccount =  ctxObject.CreateInstance("{ObjB.ProgID}")

and C must be initialized the same way.  
Neither A or B should then be calling SetCommit() or SetAbort() if further objects are going to be initialized AFTER that.

Sorry for the confusion.
0
 

Author Comment

by:reader
ID: 10652439
That is exactly what I've been doing, and I still don't know why I am getting that error!
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Expert Comment

by:Snarf0001
ID: 10652503
At what point in the code are you committing (or aborting) the transaction?

What exactly is the sequence that these objects go through?  You mentioned that calls between A and B were numerous.  Does A make calls to B at different times and intervals depeding on other code or is it a strict sequence of calls one after the other?
0
 

Author Comment

by:reader
ID: 10654192
The asp page calls A. A calls B a number of times. B calls C a number of times. The transaction should start in A, and end in A (finally).

Can the error be the result of an incorrect SQL call, rather than the reason of the SQL call not executing?

The interesting this is that when I made the mode of A 'not an MTS object', even then the transactionseemed to start, and I got the same error ..
0
 
LVL 22

Expert Comment

by:Snarf0001
ID: 10657431
That is possible.  If there was sql error occured, that would cause the entire transaction to rollback and terminate there.
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 11023283
PAQed, with points refunded (500)

PashaMod
Community Support Moderator
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now