Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test for db connection 2

Status
Not open for further replies.

Gamera99

Programmer
May 17, 2001
59
JP
I want to test for a good DB connection in the session_onstart() portion of my global.asa file, then redirect a user to a "database unavailable" page when the user hits the default.asp.

Does anyone know a good test for the connection object, rather than having to look at the "For Each mErr In mConn.Errors" error collection? I'm wondering if there is a single test like mconn.isactive, etc.

Thanks if anyone can help.
 
try
conn.state

it returns a boolean stating whether the connection is open or not.

hope this helps
leo

 
this might be a helpful template.
(not alot of people know about the state method strangly enough)

Conn.Open....
If not Conn is nothing then
if Conn.State <> 0 then
RS.Open &quot;...&quot;, Conn, ...
if not RS is nothing then
if RS.State <> 0 then
if not RS.EOF and not RS.BOF then
RS.MoveFirst
....
do whatever you want here
....
end if
end if
end if
end if
end if Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Thanks very much; that is an interesting chunk of statements.
I have always been testing for null recordsets like:
if not (rs.BOF and rs.EOF) then...
 
Well you cant do EOF or BOF if the object doesnt exist (nothing), but you cant do it either if the object is closed (state = 0) but you cant check for the State if the object exist

so clearly I do

if exist
if closed
if empty
.... Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
If I try to open a connection,
>> conn.open connectionstring <<
the page will fail right there if the database is not available.

What I need is some kind of &quot;willExecute&quot; method or event. I can't wait for the page to find out that the database is not available; or if I can, I don't know how to trap the error.
 
why not at the top of the page

on error resume next

and occasionally throughout your program you check for errors yourself

------------
if Err.number <> 0 then
Response.write &quot;Connection could not be opened&quot;
Err.clear
... whatever else you need to do...
end if

I generally in some of my pages do this only I have the Error reported at the bottom of the page in a comment block. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top