Solved

DB connectivity test and page redirection if connection failed

Posted on 2008-10-16
9
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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