Subject Re: Re: [IBO] FBServer has a GPFault (Whats wrong with my code)
Author gkrishna@jlmatrix.com
<not relevant to the discussion>
This was one of those "fools rush in where angels fear to tread" projects
I was a VB/SQLServer programmer and suddenly switched to Delphi and Firebird.
So I was bootstrapping myself in all kinds of areas.
Now the app has reached a stage where the users are happy with it.
I am unhappy because it seems to be held together with string and sticky tape.
I have sort of taken a breather from adding functionality and trying to make the app more robust.
There are all kinds of kludges in the code that I ignored because I was still learning Delphi and Firebird
So No Holds Barred comments are welcome.
I have been lurking on this list for a long time and really appreciate the efforts that somebody like Helen puts in answering silly questions. This kind of sharing of information is something that I really admire.
I have recently started popping up with strange questions. But as I said these are all attempts to the make application more robust.

The only point I would like to make is that I do spend a lot of time really trying to fix things on my own. I dont use the list as "on line help".
</not relevant to the discussion>


>No, it's a problem with your application, not a database problem. If you
>post in ib-support I will move you back here.

Yes, Thats why the subject is "what is wrong with my code"<g>

>My initial observation of your code is that it is an unholy jumble of
>native IBO, TDataset-compatible IBO and IBXpress. IOW, your AVs are coming
>from your Delphi application - most likely from the utter confusion of
>connections and transactions you have there....and that's only in the code
>we can actually *see*.

Ok Regarding the unholy jumble. Let me put down my broad brush thoughts on what I have done and please let me know if I am wrong and need to correct what I have done.

I want TDataset compatible recordsets because I use a lot of bound controls.

I am using TIB_Connection instead of TIBODatabase because
<quote from help file for TIBODatabase>
It is intended for ease of migration from the BDE to IBO but it is encouraged that you eventaully replace it with a TIB_Connection component as soon as you are ready to take full control of all transactions for the connection.
</quote from help file for TIBODatabase>

I do need more control over my transactions so I decided to use TIB_Connection.
Is this wrong. Should I stick to TIBODatabase if I need TDataset compatible recordsets.

FBServer.exe has a GPFault NOT my application.
When my application is executing the particular line, FBServer will die giving a GP Fault.
My applications will trap the error and exit.
>> Except on e:exception Do
>> Application.terminate;

That is why I was wondering whether I should post this in ib-support as well.

>Not sure why you need to drag in an IBDatabase in Section 4 (which will
>certainly give you a new connection each time you create it); but in that
>block of code you have three try.. keywords + one except and one finally,
>i.e. you have one improperly finished try block.

I am using IBX for finding out various things like PageSize, number of pages etc.
So I need a TIBDatabaseInfo. A TIBDatabaseInfo needs a IBDatabase.

FBServer will continue to run if there is one connection after both rs.open and transaction.executeimmediate are run
FBServer will give a GPFault if there are two connections after both rs.open and transaction.executeimmediate ( My feeling is that there should have only one connection because they are both referring to the same TIB_Connection object)
FBSever will continue to run if 2 connections are shown when the IBDatabase connects.


Hmm There are actually two excepts and one finally. The cut and paste into the mail client caused the indenting to become a mess.
I think you did not notice the except with the application.terminate.

>Also in that section you are referencing two objects before they have been
>created.
>IBDB:=nil;
>DbInfo:=nil;
>Both would cause an AV but the first one will crash the program before the
>second one gets a chance to do it.

And these two statements are head scratchers for me as well. They don't AV.
I will tell you why they are there.
If I use assigned() to check these variable BEFORE I create() them it will return true unless I initialise them to nil.
I normally test with assigned() to free objects in the finally section and I WILL get an AV in the finally block if an error has made the pointer jump to the finally section before the create statement for these objects are executed.

If anybody could enlighten me on this strange behaviour I would be happy.


>This looks weird too:
>CurrentNoOFDBCxns := DbInfo.UserNames.Count-1;

I have some kind of server application. So I want to display to the user the number of clients connected, that is why I am reducing the count by one.


>In any case, you can get the *correct* count without resorting to
>IBX. Once you get your data access objects sorted out (using TIBODatabase
>instead of TIB_Connection, you only have to read the Users property (a
>TStrings) to count the usernames logged in...

<Quote from the users property help from TIBODatabase>
This seems to only provide a listing of users who are logged in to the server from the machine that is making the request. You only get a complete listing if you run the program from the server locally.
</Quote from the users property help from TIBODatabase>

This is why I am using DBInfo


>That's not all, actually. The transactions are a dog's dinner...

Would love to receive one of your great mails which make everything fall in place
I have read so many of those on this list


>Helen


GK

>From : Helen Borrie <helebor@...>
>To : IBObjects@yahoogroups.com
>Date : 29/03/2003 01:17:47 PM
>Subject : Re: [IBO] FBServer has a GPFault (Whats wrong with my code)

>At 12:32 PM 29/03/2003 +0530, you wrote:
>>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