Solved

DB connectivity test and page redirection if connection failed

Posted on 2008-10-16
9
571 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:eaweb
  • 5
  • 4
9 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
Comment Utility
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
0
 

Author Comment

by:eaweb
Comment Utility
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
0
 
LVL 32

Expert Comment

by:Daniel Wilson
Comment Utility
Please show the actual classic ASP code you're using that gets this result.

Thanks.
0
 

Author Comment

by:eaweb
Comment Utility
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
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 32

Expert Comment

by:Daniel Wilson
Comment Utility
Which is line 15?  Might line 15 be something before the code you posted?
0
 

Author Comment

by:eaweb
Comment Utility
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
=======
0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
Comment Utility
Then the objConn.Open line is the place for the error trap:




 

dim objConn,  strDataSourceName      

Set objConn = Server.CreateObject("ADODB.Connection")
 

'create a database connection

objConn.connectionstring = strDataSourceName

on error resume next

objConn.Open

            if err.number <> 0 then

                  'login with no database connection page

                  Response.Redirect("lwndbcp.asp")

            end if

Open in new window

0
 

Author Comment

by:eaweb
Comment Utility
so, i dont have to make check using below query code?

strQueryCheckDBConnection = "Select getdate()"
oRsQueryCheckDBConnection = objConn.Execute(strQueryCheckDBConnection)
0
 
LVL 32

Expert Comment

by:Daniel Wilson
Comment Utility
Yeah, I guess not.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now