How to handle "Error writing data to the connection" ?

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: How to handle "Error writing data to the connection" ?

Post by ViktorV » Mon 14 Aug 2017 10:26

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;

sugi
Posts: 43
Joined: Wed 07 Dec 2016 02:05

Re: How to handle "Error writing data to the connection" ?

Post by sugi » Tue 15 Aug 2017 01:21

After many times of tried & error, finally, I got it worked as expected.
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 ;
}
//---------------------------------------------------------------------------
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.

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

Re: How to handle "Error writing data to the connection" ?

Post by ViktorV » Tue 15 Aug 2017 09:41

Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.

Post Reply