This behavior is due to the use of pooling in your sample. In this case, to solve the issue, please set the TIBCConnection.PoolingOptions.Validate property to True. For example:
ConnDba-> PoolingOptions->Validate = true;
How to handle "Error writing data to the connection" ?
Re: How to handle "Error writing data to the connection" ?
After many times of tried & error, finally, I got it worked as expected.
Here is the final codes that worked for me :
Notes :
1) Using transaction set to iblReadCommitted instead of iblReadOnlyReadCommitted
2) Memdata not included
3) RetryMode = rmReconnectExecute in my case still raised an exception when network connection is not available during execution SQL commands to remote server.
Those are different from suggestion from Help file, I don't know why it worked, maybe Help file is out of date or is was because using pooling options, etc.
Anyway, thanks for your help, this VCL is a great tools to build app that database is located in a remote server.
Here is the final codes that worked for me :
Code: Select all
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "DBAccess"
#pragma link "IBC"
#pragma link "MemDS"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TrsDba->IsolationLevel = iblReadCommitted;
ConnDba->Pooling = true;
ConnDba->PoolingOptions->Validate = true;
ConnDba->Options->LocalFailover = true;
ConnDba->Options->DisconnectedMode = true;
ConnDba->DefaultTransaction = TrsDba;
ConnDba->Open();
Q->CachedUpdates = true;
Q->Transaction = TrsDba;
Q->Close();
Q->Open();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnSaveClick(TObject *Sender)
{
const TCustomDADataSet* Tables[1] = {Q};
try
{
if (Q->State == dsEdit || Q->State == dsInsert)
Q->Post();
ConnDba->ApplyUpdates(Tables,0);
ShowMessage("OK");
}
catch (Exception &exception)
{
ShowMessage("**" + exception.Message+"**");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnRefreshClick(TObject *Sender)
{
try
{
Q->Close();
Q->Open();
ShowMessage("refresh OK");
}
catch(...)
{
ShowMessage("refresh : no internet connection!");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ConnDbaConnectionLost(TObject *Sender,
TComponent *Component, TConnLostCause ConnLostCause,
TRetryMode &RetryMode)
{
static short loss=1;
lbllost->Caption = AnsiString(loss);
lblttl->Caption = AnsiString(ConnLostCause);
loss++;
RetryMode = rmReconnectExecute ;
}
//---------------------------------------------------------------------------
1) Using transaction set to iblReadCommitted instead of iblReadOnlyReadCommitted
2) Memdata not included
3) RetryMode = rmReconnectExecute in my case still raised an exception when network connection is not available during execution SQL commands to remote server.
Those are different from suggestion from Help file, I don't know why it worked, maybe Help file is out of date or is was because using pooling options, etc.
Anyway, thanks for your help, this VCL is a great tools to build app that database is located in a remote server.
Re: How to handle "Error writing data to the connection" ?
Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.
Feel free to contact us if you have any further questions about our products.