Answer the question
In order to leave comments, you need to log in
How to organize work with the FireBird database from several threads?
I'm digging towards TIBConnectionbroker, but I can't figure out how to properly organize the work. Console application.
Here are a few lines from the code.
Application itself:
program main;
{$APPTYPE CONSOLE}
uses
IBX.IBConnectionBroker,
MyThread in 'MyThread.pas';
var
Thread1, Thread2: TMyThread;
ConnectionBroker: TIBConnectionBroker;
begin
ConnectionBroker:=TIBConnectionBroker.Create(nil);
ConnectionBroker.DatabaseName:='C:\DataBase.fdb';
ConnectionBroker.Params.Clear;
ConnectionBroker.Params.Add('user_name=SYSDBA');
ConnectionBroker.Params.Add('password=masterkey');
Thread1:=TMyThread.Create(True);
Thread1.fBroker:=ConnectionBroker;
Thread1.Resume;
Thread2:=TMyThread.Create(True);
Thread2.fBroker:=ConnectionBroker;
Thread2.Resume;
end;
unite MyThread;
interface
uses
IBDatabase,
IBCustomDataSet,
IBX.IBConnectionBroker;
type
TMyThread = class(TThread)
private
fDataBase: TIBDatabase;
fTransaction: TIBTransaction;
fDataSet: TIBDataSet;
protected
procedure Execute; override;
published
fBroker: TIBConnectionBroker;
end;
implementation
procedure TMyThread.Execute;
begin
fDatabase:=fBroker.GetConnection; // Тут вылетает Exception class $C0000005 with message 'access violation at 0x0069dc06: read of address 0x00000000'
fTransaction:=TIBTransaction.Create(nil);
fTransaction.DefaultDatabase:=fDataBase;
fDataSet:=TIBDataSet.Create(nil);
fDataSet.Database:=fDataBase;
fDataSet.Transaction:=fTransaction;
end;
Answer the question
In order to leave comments, you need to log in
I found what's wrong.
After creating and setting parameters, TIBConnectionBroker
it was necessary to initialize it.
What ended up happening:
ConnectionBroker:=TIBConnectionBroker.Create(nil);
ConnectionBroker.DatabaseName:='C:\DataBase.fdb';
ConnectionBroker.Params.Clear;
ConnectionBroker.Params.Add('user_name=SYSDBA');
ConnectionBroker.Params.Add('password=masterkey');
ConnectionBroker.Init; // <- Вот он, мой геморрой
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question