Article View: borland.public.cppbuilder.database.ado
Article #5018Re: Connection dead
From: Jurko
Date: Wed, 22 Aug 2001 11:40
Date: Wed, 22 Aug 2001 11:40
62 lines
3007 bytes
3007 bytes
Hmm I did this in another way... I wrapped a TADOConnection object in
a TSmartConnection object which holds the normal ADO connection and
which executes all my commands and opens datasets... now when I execute
a command or open a dataset that object can try to reconnect for a specified
number of times on failures, which takes care of those unexplainable
connection
drops...
Before I did this I had to restart my app every time something caused the
connection to drop... (for example... someone pulled out a cable while the
program was trying something... it's unbelievable how many times people
do this :-))) )
This has a plus side that I don't have to duplicate the reconnection code on
every place where I execute commands or open datasets...
Just my two cents worth...
Jurko
"Harold Howe (TeamB)" <hhowe@bcbdev.com> wrote in message
news:3B6DBF1D.82FB6F3@bcbdev.com...
> Henrik Franz๏ฟฝn wrote:
> >
> > I have a problem with an ADO connection. I connect to a database. I can
get
> > all tables, but after a this i get a error. It seems like the
> > connectionobject is dead (NIL)..
>
> I have an app that I want to keep connected to the database at all times.
Its a
> server type of app. After a while, SQLServer just seems to drop the
connection on me.
> To combat this, I use code like this. Maybe you can try something similar.
>
> ADOdataset->Parameters->ParamByName("foo")->Value = "bar";
> try
> {
> ADOdataset->Open();
> }
> catch (EOleError &e)
> {
> // if an OLE error occurs, then perhaps we have lost our ADO
connection,
> // toggle the connection object and retry
> try
> {
> ADOdataset->Connection->Connected = false;
> ADOdataset->Connection->Connected = true;
> ADOdataset->Open();
> }
> catch (Exception &e)
> {
> // nothing we can do really, just rethrow and maybe log an
> // error message
> throw;
> }
> }
>
> You can bundle this all into a function to keep your code clean.
>
> Harold Howe [TeamB]
> http://www.bcbdev.com
Technical Details
Message-ID:
<3b839a24$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3b5fdf14_1@dnews> <3B6DBF1D.82FB6F3@bcbdev.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10698b,6744f1abb7486ef6 X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2001-08-22 04:42:35 PST Reply-To: "Jurko" <Jurko@ve-mil.hr> From: "Jurko" <Jurko@ve-mil.hr> Newsgroups: borland.public.cppbuilder.database.ado References: <3b5fdf14_1@dnews> <3B6DBF1D.82FB6F3@bcbdev.com> Subject: Re: Connection dead Date: Wed, 22 Aug 2001 13:40:34 +0200 Lines: 64 Organization: Ve-mil X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 195.29.221.130 Message-ID: <3b839a24$1_1@dnews> X-Trace: dnews 998480420 195.29.221.130 (22 Aug 2001 04:40:20 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnews