Strange invalid transaction handle Error

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sugi
Posts: 43
Joined: Wed 07 Dec 2016 02:05

Strange invalid transaction handle Error

Post by sugi » Tue 15 Aug 2017 04:32

VCLs Settings :

Code: Select all

/* Connection Settings*/
ConnDba->Pooling = true;
ConnDba->PoolingOptions->Validate = true;
ConnDba->Options->LocalFailover = true;
ConnDba->Options->DisconnectedMode = true;

/* TIBCQuery Seetings*/
T_JRNL1->CacheUpdates = true;
T_JRNL2->CacheUpdates = true;
Database location is on remote server, connected via Internet.
When executed this code :

Code: Select all

void __fastcall TInpBnkInOtFrm::OpnJrn1Done(TObject *Sender)
{
   if(T_JRNL1->IsEmpty()) T_JRNL1->Append();

   OpnDt *Dt4 = new OpnDt(true);
   Dt4->Dt = T_JRNL2;
   Dt4->Id = T_JRNL1JRNL1ID->AsInteger;
   Dt4->Resume();
   Dt4->OnTerminate = OpnJrn2Done;
}
//---------------------------------------------------------------------------

Sometime, runs OK, but mostly got Invalid transaction handle Error.

That codes, basically open an Query on another thread, here is the thread code :

Code: Select all

__fastcall OpnDt::OpnDt(bool CreateSuspended)
   : TThread(CreateSuspended)
{
   FreeOnTerminate = true;
}
//---------------------------------------------------------------------------
void __fastcall OpnDt::Execute()
{
   Dt->Close();
   Dt->ParamByName("id")->Value = Id;
   Dt->Open();
}
//---------------------------------------------------------------------------
If I pause thread execution for a second, changed codes to this :

Code: Select all

void __fastcall TInpBnkInOtFrm::OpnJrn1Done(TObject *Sender)
{
   if(T_JRNL1->IsEmpty()) T_JRNL1->Append();
   PauseInSec(1); -> this will pause app for a second
   OpnDt *Dt4 = new OpnDt(true);
   Dt4->Dt = T_JRNL2;
   Dt4->Id = T_JRNL1JRNL1ID->AsInteger;
   Dt4->Resume();
   Dt4->OnTerminate = OpnJrn2Done;
}
//---------------------------------------------------------------------------
App runs OK. Why ?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Strange invalid transaction handle Error

Post by ViktorV » Tue 15 Aug 2017 09:41

IBDAC is thread-safe, but the restriction is that you cannot use one connection (the TIBCConnection component) in several threads, and you should use a separate connection in each thread.

Post Reply