Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to insert Master/Detail records inside the same transaction

Status
Not open for further replies.

Mike42

Programmer
Feb 22, 2001
10
DE
Hello,

I am new to MTS programming and tried to insert a master record with a detail record inside the same MTS transaction. The detail table has an foreign key constraint to the master table.

So I built two MTS components (in the same DLL) with VC6 and set their transactional attribute to required. Both components are completely stateless. They get called by a simple COM Win32 console application.

The master component opens an ADO connection, inserts a record and closes the connection (no problem here). Then it creates and calls the second object to insert the detail record (Primary/Foreign key is generated as GUID). The detail Object chooses the same strategy (generate key, open, insert, close).

But the second object will not use the connection of the first object, so any try to insert the detail record will lead to a constraint violation and cause the transaction to be rolled back (as expected in case of any error).

I tried to delay the close of the master connection, but this brought no change. Also moving the detail object creation to IObjectControl::Activate was useless.

I am using MTS 2.0 SP1 on NT4 Workstation against an Informix 7.31UC4 Dynamic Server running on SCO OpenServer 5.0.5. The database connection is made via ADO (MDAC 2.1) / OLEDB for ODBC / Informix Client SDK 2.50 (Informix ODBC 3.32).

Both the detail object and the ADO connection object are created via the current ObjectContext.

So the questions:
1. Has anyone got this to work with MTS on any Database backend ?
2. Are there any pitfalls I oversaw ?
3. Any idea for an alternate master/detail insertion pattern that ensures referencial integrity on the database backend ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top