PC Review


Reply
Thread Tools Rate Thread

Checking for open db

 
 
John
Guest
Posts: n/a
 
      6th Aug 2007
Hi

In my app I am opening a db connection then running a set of queries and at
the end closing the db connection. Once in a while a query fails to run
saying database connection is closed. How can I ensure that db connection is
confirmed open before running a query? Will

dbconn.close
dbconn.open

before running a query do the trick or do I need to make more comprehensive
checks?

Thanks

Regards


 
Reply With Quote
 
 
 
 
Spam Catcher
Guest
Posts: n/a
 
      6th Aug 2007
"John" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> before running a query do the trick or do I need to make more
> comprehensive checks?


Check the state of the connection.

I believe connection.state will give you the connection state. Just make
sure the connection is "Open".

You can also wrap your call in a try/catch - if it fails, repeat the call.

Lastly you may want to wrap your SQL in a transaction to prevent orphaned
records from being inserted.
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      6th Aug 2007
Hi

Thanks. Not sure about the last point though, How do I implement
transactions? Any link etc would be appreciated.

Thanks

Regards

"Spam Catcher" <(E-Mail Removed)> wrote in message
news:Xns9983EAED4EB32usenethoneypotrogers@127.0.0.1...
> "John" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>> before running a query do the trick or do I need to make more
>> comprehensive checks?

>
> Check the state of the connection.
>
> I believe connection.state will give you the connection state. Just make
> sure the connection is "Open".
>
> You can also wrap your call in a try/catch - if it fails, repeat the call.
>
> Lastly you may want to wrap your SQL in a transaction to prevent orphaned
> records from being inserted.



 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      6th Aug 2007
John,

In fact is this a failure in your program, you control the program, so
somewhere you have not closed or opened it. I try to be very secure always
to have my database actions in small methods, wherin is the open of the db
as the close of the db.

dbopen and dbclose are C (SQL) commands

dbconnection.open and dbconnection.close methods of the mustinherit
Connection class.

Cor

"John" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Hi
>
> In my app I am opening a db connection then running a set of queries and
> at the end closing the db connection. Once in a while a query fails to run
> saying database connection is closed. How can I ensure that db connection
> is confirmed open before running a query? Will
>
> dbconn.close
> dbconn.open
>
> before running a query do the trick or do I need to make more
> comprehensive checks?
>
> Thanks
>
> Regards
>


 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      6th Aug 2007
On Aug 5, 11:09 pm, "John" <J...@nospam.infovis.co.uk> wrote:
> Hi
>
> Thanks. Not sure about the last point though, How do I implement
> transactions? Any link etc would be appreciated.
>
> Thanks
>
> Regards
>
> "Spam Catcher" <spamhoney...@rogers.com> wrote in message
>
> news:Xns9983EAED4EB32usenethoneypotrogers@127.0.0.1...
>
> > "John" <J...@nospam.infovis.co.uk> wrote in
> >news:(E-Mail Removed):

>
> >> before running a query do the trick or do I need to make more
> >> comprehensive checks?

>
> > Check the state of the connection.

>
> > I believe connection.state will give you the connection state. Just make
> > sure the connection is "Open".

>
> > You can also wrap your call in a try/catch - if it fails, repeat the call.

>
> > Lastly you may want to wrap your SQL in a transaction to prevent orphaned
> > records from being inserted.


You can search the help for DbTransaction (replace "Db" with your
provider (Sql/OleDb) for more specific help) or go to msdn.com and
search there. Both will bring up Microsoft's documentation for this.

Also, I believe it was Bill Vaughn that said that connection.State
will only tell you what it "thinks" it's state is - so this could
return a state of Open even if the connection has been lost - so make
sure you use a try.. catch just in case.

Thanks,

Seth Rowe

 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      6th Aug 2007
> dbopen and dbclose are C (SQL) commands

Huh?

I think you misread something...

Thanks,

Seth Rowe

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      7th Aug 2007
Seth,

> I think you misread something...


Is this information wrong or did I understood it wrong?
http://msdn2.microsoft.com/en-us/library/aa937054(sql.80).aspx

Cor

"rowe_newsgroups" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
>> dbopen and dbclose are C (SQL) commands

>
> Huh?
>
> I think you misread something...
>
> Thanks,
>
> Seth Rowe
>


 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      7th Aug 2007
On Aug 6, 11:18 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
> Seth,
>
> > I think you misread something...

>
> Is this information wrong or did I understood it wrong?http://msdn2.microsoft.com/en-us/library/aa937054(sql.80).aspx
>
> Cor
>
> "rowe_newsgroups" <rowe_em...@yahoo.com> schreef in berichtnews:(E-Mail Removed)...
>
> >> dbopen and dbclose are C (SQL) commands

>
> > Huh?

>
> > I think you misread something...

>
> > Thanks,

>
> > Seth Rowe


I didn't say your information was wrong - I'm just wondering why you
shared it in the first place. The OP never mentioned C or the dbopen/
dbclose commands. I thought you misread dbconn.Open as dbopen and
posted the wrong information.

Thanks,

Seth Rowe

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - checking if a presentation is already open simonc Microsoft Powerpoint 2 22nd May 2008 02:16 PM
Checking for open db John Microsoft VB .NET 7 7th Aug 2007 11:31 AM
Checking for see if IE is open ... =?Utf-8?B?MTBfYV9j?= Microsoft Windows 2000 CMD Promt 5 5th Jan 2005 03:16 PM
Checking if a query is currently open Mark Microsoft Access Queries 0 24th Aug 2004 04:19 PM
Checking for open workbook... Squid Microsoft Excel Programming 7 28th Feb 2004 01:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:53 AM.