Link to home
Start Free TrialLog in
Avatar of eaweb
eawebFlag for undefined

asked on

DB connectivity test and page redirection if connection failed

hi

i am running queries in both asp.net and classic asp pages,

how can i verify DB connectivity and redirect users to an custom error page if the test fail before executing any queries.

i need to do this check for both asp.net and classic asp pages using VB code style
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

ASP.Net:

Try
 'Create / Open a connection
 'execute a "Select getdate()" or some other super-light query
Catch ex as Exception
 'Redirect to error page
End Try

Classic ASP:

On error resume next
'create / open a connection
' 'execute a "Select getdate()" or some other super-light query
if err.number <> 0 then
  'Redirect to error page
end if
Avatar of eaweb

ASKER

when test in classic asp i get this error page
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80004005)
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
/WEBDEV/code/devwebscripts/devaccmgr/lwuapcsp.asp, line 15

i tested it with the sql server stopped.

haven't tested it yet in asp.net
Please show the actual classic ASP code you're using that gets this result.

Thanks.
Avatar of eaweb

ASKER

On error resume next
            strQueryCheckDBConnection = "Select getdate()"
            oRsQueryCheckDBConnection = objConn.Execute(strQueryCheckDBConnection)
            if err.number <> 0 then
                  'login with no database connection page
                  Response.Redirect("lwndbcp.asp")
            end if
Which is line 15?  Might line 15 be something before the code you posted?
Avatar of eaweb

ASKER

line 15 is when i try to open a connection:
strDataSourceName is part of an include file.
with the server started i dont get errors, but when not available i get the page error

dim objConn,  strDataSourceName      
Set objConn = Server.CreateObject("ADODB.Connection")

'create a database connection
objConn.connectionstring = strDataSourceName
objConn.Open'=====line 15


=======
objConn.Open
=======
ASKER CERTIFIED SOLUTION
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eaweb

ASKER

so, i dont have to make check using below query code?

strQueryCheckDBConnection = "Select getdate()"
oRsQueryCheckDBConnection = objConn.Execute(strQueryCheckDBConnection)
Yeah, I guess not.