Solved

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

Posted on 2004-03-22
9
1,186 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 23

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 23

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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
 
LVL 23

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 23

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

733 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