Problem with TIBCSQL.Execute method in multithread applicati

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
adm.nilser
Posts: 10
Joined: Sat 09 Jul 2011 15:53
Location: Brasil

Problem with TIBCSQL.Execute method in multithread applicati

Post by adm.nilser » Sat 09 Jul 2011 16:45

Hello, i'm testing the lastest IBDAC version with a multithread application, and when i try to execute TIBCSQL.Execute method i have a access violation exception.
i tested the method with a simple application, then working fine.
Any idea about this issue??

AndreyZ

Post by AndreyZ » Mon 11 Jul 2011 09:50

Hello,

Such problems can occur in the multithreaded application if you are using one connection in several threads. To solve the problem, you should have a separate connection in each thread.

adm.nilser
Posts: 10
Joined: Sat 09 Jul 2011 15:53
Location: Brasil

Post by adm.nilser » Mon 11 Jul 2011 19:05

Hi, AndreyZ!!

there's a unique connection for each thread, I already checked this.
I see in the othes topics that some users has the similar problem.

Any idea?

AndreyZ

Post by AndreyZ » Tue 12 Jul 2011 06:23

Please try composing a small sample to demonstrate the problem and send it to andreyz*devart*com, including a script to create server objects. Also please specify the following:
- the exact version of your IDE;
- the exact version of Firebird or InterBase.

imeyer
Posts: 9
Joined: Mon 01 Mar 2010 16:24

Post by imeyer » Tue 19 Jul 2011 12:55

Hello adm.nilser

i have had the same problem and solved it in this way

change in the IBCall.pas the line 2840(2841) like this

EnsureThreadSafety:=false;
// EnsureThreadSafety := (Version = 6);

this works for me my multithreading application is running a connection in each thread

adm.nilser
Posts: 10
Joined: Sat 09 Jul 2011 15:53
Location: Brasil

Post by adm.nilser » Wed 20 Jul 2011 02:31

I'm using the demo version.
I haven't the source code to make this changing.
But, I can change the ThreadSafetyClientLibrary variable value to False. Is it the same thing??

imeyer
Posts: 9
Joined: Mon 01 Mar 2010 16:24

Post by imeyer » Wed 20 Jul 2011 16:06

no that's not the same thing i tried this as well but it do not work in the way i excpected it. So i started to debug it and have found out that the mention
Variable "EnsureThreadSafety" is become always true in my constalation.

After changin it to false the application works fine.

AndreyZ

Post by AndreyZ » Thu 21 Jul 2011 07:12

The point is that the client library can be not threadsafe, and that can cause different random errors in a multithreaded application. The EnsureThreadSafety variable helps to avoid these errors. If the client library isn't threadsafe, IBDAC implements thread-safety by itself. For example, if you are using Firebird 2.5, IBDAC won't implement thread-safety by itself, but if you are using any previous Firebird version, IBDAC will implement thread-safety.

to imeyer:
In the latest IBDAC version 3.60.0.24 we fixed the problem with the EnsureThreadSafety variable for RAD Studio 2009 and higher. Please try using the IBDAC version 3.60.0.24 and check if the problem persists.

to adm.nilser:
The problem you described can be caused by different reasons. That's why it's better if you compose a small sample that demonstrates this problem and send it to me. This way I will be able to investigate the problem and find a solution. Please provide me all information I asked you in my previous post.

adm.nilser
Posts: 10
Joined: Sat 09 Jul 2011 15:53
Location: Brasil

Post by adm.nilser » Tue 26 Jul 2011 12:15

Hi, I discovered the problem. It's occurs when I try to use blob params.
I implemented a class inherited from TIBCQuery called TIBXQuery that declares a method called SetParam.

TIBXQuery = class(TIBCQuery)
public
procedure SetParam(AParam: String; AValue: Variant; AType: TFieldType);
end;

The SetParam method's code is:

procedure TIBXQuery.SetParam(AParam: String; AValue: Variant; AType: TFieldType);
var
lParam: TParam;
begin
lParam := ParamByName(AParam);
lParam.DataType := AType;
lParam.Value := AValue;
end;

If local variable lParam is a blob param, a exception occurs.
This method only works if I change the AValue parameter's type to String and set lParam variable as lParam.AsMemo := AValue;

I'm using the version 3.60.0.24 of IBDAC.

Any sugestion??

AndreyZ

Post by AndreyZ » Wed 27 Jul 2011 10:16

To solve the problem, you should use TIBCParam instead of TParam in the following way:

Code: Select all

procedure TIBXQuery.SetParam(AParam: String; AValue: Variant; AType: TFieldType);
var
  lParam: TIBCParam;
begin
  lParam := ParamByName(AParam);
  lParam.DataType := AType;
  lParam.Value := AValue;
end;

adm.nilser
Posts: 10
Joined: Sat 09 Jul 2011 15:53
Location: Brasil

Post by adm.nilser » Thu 28 Jul 2011 11:05

Thanks, Andreyz!!

This code working fine.

AndreyZ

Post by AndreyZ » Thu 28 Jul 2011 11:14

Feel free to contact us if you have any further questions about IBDAC.

Post Reply