Page 1 of 1

"A connection with the transaction manager was lost"

Posted: Mon 29 Dec 2008 15:16
by Jeff Gallant
SDAC 4.70
Delphi 2006

I am trying to follow the advice given for my previous issue in this forum (Simple multi-user problem locks/transactions)

I have the following code:

txnNextCB.AddConnection(qryNextCB.Connection);
txnNextCB.StartTransaction;
qryNextCB.open;

where txnNextCB is a TMStransaction and qryNextCB is a TMSquery.

txnNextCB has been put on the form with all the defaults apart from its name and this is the first time it is referenced - no other connections have been added.

When I run the code, I get:

"A connection with the transaction manager was lost"

If I comment out the code referring to the transaction

// txnNextCB.AddConnection(qryNextCB.Connection);
// txnNextCB.StartTransaction;
qryNextCB.open;

the query runs okay indicating that qryNextCB.Connection is connected and works.

What am I doing wrong?

Posted: Tue 30 Dec 2008 12:23
by Dimon
I can not reproduce the problem.
Please check if the following code works:

Code: Select all

  qryNextCB.Connection.StartTransaction;
  qryNextCB.open;

"A connection with the transaction manager was lost"

Posted: Wed 31 Dec 2008 09:35
by Jeff Gallant
Thanks Dimon, that got me through that point but now my code is:

txnNextCB.AddConnection(qryNextCB.Connection);
qryNextCB.Connection.StartTransaction;
qryNextCB.open;
qryNextCB.Lock(ltExclusive);

some other code that uses FieldByName to capture data from the selected record

qryUpdateCB.Connection:=qryNextCB.Connection;
qryUpdateCB.execute; // Updates record selected by qryNextCB
qryNextCB.Connection.Commit;
qryNextCB.UnLock;

However, when it executes the unlock I get

“the ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION”

I've obviously still not got the hang of this.

What I am trying to do is prevent anyone else successfully selecting and locking this record until after the update is posted (the update changes the record so qryNextCB's where clause would no longer select it) so I cannot unlock the record until after the update is committed.

Assuming no-one responds today, may I wish you all a happy new year and hope that I can get this resolved early in 2009.

Best wishes

Jeff

Posted: Mon 05 Jan 2009 09:21
by Dimon
The point is that the record lock is automatically released when the transaction is committed or rolled back. Therefore you should not execute the UnLock method after executing Connection.Commit.