Solved

DB connectivity test and page redirection if connection failed

Posted on 2008-10-16
9
574 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checkbox in a dynamic GridVIew is not clickable? 5 26
encoding an href string 2 20
Select only the top record in a left join 13 35
C# LINQ ForEach() question 6 28
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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