Solved

DB connectivity test and page redirection if connection failed

Posted on 2008-10-16
9
576 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
ID: 22735815
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
ID: 22770426
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
ID: 22770589
Please show the actual classic ASP code you're using that gets this result.

Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:eaweb
ID: 22770632
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
 
LVL 32

Expert Comment

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

Author Comment

by:eaweb
ID: 22777097
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
ID: 22777133
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
ID: 22777272
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
ID: 22777513
Yeah, I guess not.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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