Subject | RE: [IBO] Re: How to reconnect to database |
---|---|
Author | Michael Horne |
Post date | 2004-01-21T21:08:30Z |
Here is a section of code that I use in my web site to reconnect when
a web request comes in. Maybe it would help you.
Good Luck
Michael L. Horne
procedure TWeb.WebModuleBeforeDispatch(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var sPathInfo:String;
bValidSession:Boolean;
ConnectionError:String;
begin
// ****************************************
// Make sure we have a DB Connection
// ****************************************
ConnectionError := '';
if (Connection1.Connected = False) or
(Connection1.VerifyConnection = False) then
begin
log('Not Connected to db so try');
Connection1.Disconnect; // found that if I did not disconnect here
could get errors
Connection1.DatabaseName := gsIBFileName;
Connection1.UserName := gsIBUserName;
Connection1.Password := gsIBPassword;
try
Connection1.Connect;
log('Connected Now');
except
on E: Exception do
begin
ConnectionError := 'Unable to connect to Database. Please notify '
+gsCompanyName+' '+gsSendMailTo+CRLF+'<br><br><br> '
+E.Message;
log('Connection Failed');
exit;
end;
end;
end;
a web request comes in. Maybe it would help you.
Good Luck
Michael L. Horne
procedure TWeb.WebModuleBeforeDispatch(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var sPathInfo:String;
bValidSession:Boolean;
ConnectionError:String;
begin
// ****************************************
// Make sure we have a DB Connection
// ****************************************
ConnectionError := '';
if (Connection1.Connected = False) or
(Connection1.VerifyConnection = False) then
begin
log('Not Connected to db so try');
Connection1.Disconnect; // found that if I did not disconnect here
could get errors
Connection1.DatabaseName := gsIBFileName;
Connection1.UserName := gsIBUserName;
Connection1.Password := gsIBPassword;
try
Connection1.Connect;
log('Connected Now');
except
on E: Exception do
begin
ConnectionError := 'Unable to connect to Database. Please notify '
+gsCompanyName+' '+gsSendMailTo+CRLF+'<br><br><br> '
+E.Message;
log('Connection Failed');
exit;
end;
end;
end;
>-----Original Message-----
>From: Andreas Bednarek [mailto:bluehorse@...]
>Sent: Thursday, January 15, 2004 11:40 AM
>To: IBObjects@yahoogroups.com
>Subject: Re: [IBO] Re: How to reconnect to database
>
>
>Hello Gerhard, thanks for reply, but I believe that's not it :-(
>
>RaiseException := False; avoids raising exception after exiting the OnError
>handler, but doesn't surpress the dialog that appears when calling
>Disconnect inside the handler which says 'Dataset is currently fetching'. I
>tried that right now to prove it.
>
>Any other suggestions?
>thanks
>Andreas
>
>
>P.S. my whole code looks like this if somebody wants to have a look:
>
>
>procedure TFormData.DatabaseFPNetError(Sender: TObject;
> const ERRCODE: Integer; ErrorMessage, ErrorCodes: TStringList;
> const SQLCODE: Integer; SQLMessage, SQL: TStringList;
> var RaiseException: Boolean);
>
>const
> boFlag : Boolean = False;
>
>begin
>
> RaiseException := True; //probably default
> if boFlag then exit;
>
> boFlag := True;
>
> if ERRCODE = 335544721 then //connection might be lost
> try
> DatabaseFPNet.Disconnect; //here it says 'Dataset is currently
>fetching'
> DatabaseFPNet.Connect;
> RaiseException := False;
> except
> end;
>
> boFlag := False;
>
>end;
>
>
>
>----- Original Message -----
>From: "gbehnke2000" <Behnke@...>
>To: <IBObjects@yahoogroups.com>
>Sent: Thursday, January 15, 2004 3:55 PM
>Subject: [IBO] Re: How to reconnect to database
>
>
>> Hallo Andreas,
>>
>> in your event handler set
>>
>> RaiseException = false
>>
>> Then the the dialog dos'nt appear.
>>
>> I found the mentionend value (335544721) also per experiments.
>>
>> Regards
>>
>> Gerhard
>>
>> -- In IBObjects@yahoogroups.com, "Andreas Bednarek" <bluehorse@d...>
>> wrote:
>> > Hello everyone!
>> >
>> > Isn't there really anybody, who knows the solution? This must be a
>> common
>> > problem. I also searched the archive but was not succesfull, so
>> I'll try it
>> > once again, maybe I'm just missing something simple, but don't know
>> what...
>> >
>> > Please how can I reconnect to DB (FB1.5 RC7) when the connection
>> has been
>> > lost? For example if the cable is disconnected and the connected
>> again.
>> > Beacuse the TIBODatabase.Connected property remains True (why?!?),
>> the only
>> > way is probably to listen to the exception (I use the IBO Data
>> Access
>> > components to connect do DB)
>> >
>> > I implemented an TIBODatabase.OnError event handler, where it looks
>> roughly
>> > like this:
>> >
>> > if ERRCODE = 335544721 then begin
>> > Disconnect;
>> > Connect;
>> > end;
>> >
>> >
>> > This works pretty well EXCEPT that calling Disconnect displays an
>> > message box 'Dataset is currently fetching' and you have to
>> > click 'OK' !!! For me It is necessary to avoid that dialog.
>> >
>> > I'm also not sure about the value 335544721 which has been
>> discovered
>> > empiricaly.
>> >
>> >
>> > Do you know how to correctly reconnect to a (remote) FB database
>> using
>> > TIBODatabase?
>> >
>> > thank you very much
>> > Andreas
>>
>>
>>
>___________________________________________________________________________
>> IB Objects - direct, complete, custom connectivity to Firebird or
>InterBase
>> without the need for BDE, ODBC or any other layer.
>>
>___________________________________________________________________________
>> http://www.ibobjects.com - your IBO community resource for Tech Info
>papers,
>> keyword-searchable FAQ, community code contributions and more !
>>
>>
>> Yahoo! Groups Links
>>
>> To visit your group on the web, go to:
>> http://groups.yahoo.com/group/IBObjects/
>>
>> To unsubscribe from this group, send an email to:
>> IBObjects-unsubscribe@yahoogroups.com
>>
>> Your use of Yahoo! Groups is subject to:
>> http://docs.yahoo.com/info/terms/
>>
>>
>
>
>___________________________________________________________________________
>IB Objects - direct, complete, custom connectivity to Firebird or InterBase
> without the need for BDE, ODBC or any other layer.
>___________________________________________________________________________
>http://www.ibobjects.com - your IBO community resource for Tech
>Info papers,
>keyword-searchable FAQ, community code contributions and more !
>
>Yahoo! Groups Links
>
>To visit your group on the web, go to:
> http://groups.yahoo.com/group/IBObjects/
>
>To unsubscribe from this group, send an email to:
> IBObjects-unsubscribe@yahoogroups.com
>
>Your use of Yahoo! Groups is subject to:
> http://docs.yahoo.com/info/terms/
>
>
>
>