Subject FBServer has a GPFault (Whats wrong with my code)
Author gkrishna@jlmatrix.com
Hi,

I face a strange problem.
Sometimes Firebird server crashes with an access violation.
(This happens under Windows 98 as well Windows 2000)
I am using FB Server 1.0 Build 794.

It is something that I am doing in my code which is causing this problem.

It is replicable at my end if certain conditions are met.
There are four sections of code interacting which causes the condition to be met.

I am including the four sections

In section one I am creating a connection to the database.
After that now under 98 if i click on fbserver icon on the tray I can see the number of attachments.
Firebird properties page now show number of attachments is 1

Section one
try
If Not IB_Connection1.Connected then
IB_Connection1.Connect;
except
on e:EIB_ISCError do
HandleAllErrs(self,e);
on e:Exception do
Raise;
ENd;
------------------------------------------------------------------------------------------------------


Section two is first creating a transaction.

Section two

TranMain is a global variable

if not Assigned(TranMain) then
TranMain:=TIBOTransaction.Create(self);
TranMain.IB_Connection := IB_Connection1;

TranMain.ExecuteImmediate('update tblconfiguration set NUSERS = ' + InttoStr(NumUsers) + ' , NTASKS=0, NMESSAGES=0');

TranMain.CommitRetaining ;
TranMain.refresh(false);
----------------------------------------------------

Section three is used to retrieve some information.

Section 2

var
Rs:TIBOQuery;

begin
Rs:=nil;
Try
Rs:=TIBOQuery.Create(self);
Rs.IB_Connection := IB_Connection1;
rs.SQL.Add('select DBVersion,PersonaldbVersion from tbldbconfig');
rs.Prepare;
Rs.Open;
if rs.RecordCount>0 then
begin
<do something with info from rs>
end;
finally
rs.Close;
if assigned(rs) then freeandnil(rs);

end;
end;
------------------------------------------------------------------------------
I expect that section 2 and section 3 code should not increase the number of attachments as shown on the firebird properties page.
This is true only Sometimes .
in most of the time the line

TranMain.ExecuteImmediate('update tblconfiguration set NUSERS = ' + InttoStr(NumUsers) + ' , NTASKS=0, NMESSAGES=0');

or the line

Rs.Open;

causes the number of attachments to increase (+1 each).

Not able to identify when. I am just going through the debugger. No change in the code but sometimes attachments will show 1, sometimes it will show morethan that


If the number of attachments are morethan one then a line from Section 4 will cause Firebird server to give a gp fault and shut down

Section 4
Var
IBDB:TIBDatabase;
DbInfo:TIBDatabaseInfo;
SParams:Tstrings;
DbSize:int64;
begin
Try
Try
IBDB:=nil;
DbInfo:=nil;
DbSize:=0;
IBDB:=TIBDatabase.Create(nil);
SParams:=TStringList.Create;
SParams.Add('user_name=sysdba');
SParams.Add('password=masterkey');
with IBDB Do
Begin
DatabaseName :=RServerIP + ':' + IncludeTrailingPathDelimiter(RDBPath) + RDBName;
Params:=SParams;
AllowStreamedConnected:=false;
LoginPrompt:=false;
Open ;
End;

DbInfo := TIBDatabaseInfo.Create(nil);
DbInfo.Database := IBDb;

try
CurrentNoOFDBCxns := DbInfo.UserNames.Count-1;
Except on e:exception Do
Application.terminate;
End;
Except
On E:EIBInterBaseError Do // 336331022
raise EIBInterbaseError.Create(e.SQLCode,e.IBErrorCode,'['+ inttostr(e.IBErrorCode) + ']' + e.Message);
on E:Exception Do
Raise Exception.Create(e.Message);
End;
Finally
Begin
if Assigned(IBDB) then
Begin
if IBDB.Connected then
IBDB.Connected:=false;
freeandnil(IBDB);
End;
if Assigned(DbInfo) then
FreeandNil(DbInfo);
If Assigned(sPArams) then
FreeAndnil(sparams);
End;
End;
end;
--------------------------------------------------------------
The exact line which will cause Firebird Server to crash is the following line

CurrentNoOFDBCxns := DbInfo.UserNames.Count-1;

Any help much appreciated.

Helen,
Can is cross post this in ib-support

gk