eaweb
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
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
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
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80004005)
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
/WEBDEV/code/devwebscripts
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.
Thanks.
ASKER
On error resume next
strQueryCheckDBConnection = "Select getdate()"
oRsQueryCheckDBConnection = objConn.Execute(strQueryCh eckDBConne ction)
if err.number <> 0 then
'login with no database connection page
Response.Redirect("lwndbcp .asp")
end if
strQueryCheckDBConnection = "Select getdate()"
oRsQueryCheckDBConnection = objConn.Execute(strQueryCh
if err.number <> 0 then
'login with no database connection page
Response.Redirect("lwndbcp
end if
Which is line 15? Might line 15 be something before the code you posted?
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 .Connectio n")
'create a database connection
objConn.connectionstring = strDataSourceName
objConn.Open'=====line 15
=======
objConn.Open
=======
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
'create a database connection
objConn.connectionstring = strDataSourceName
objConn.Open'=====line 15
=======
objConn.Open
=======
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so, i dont have to make check using below query code?
strQueryCheckDBConnection = "Select getdate()"
oRsQueryCheckDBConnection = objConn.Execute(strQueryCh eckDBConne ction)
strQueryCheckDBConnection = "Select getdate()"
oRsQueryCheckDBConnection = objConn.Execute(strQueryCh
Yeah, I guess not.
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