Catch unable to login to mssql connection

I have an if-then statement to catch if I am unable to make a live connection to  MSSQL database.
but I'm hitting an error now, that login is invalid.
Is there an if statement that will catch any of these too?
I only want my users to see the information once we are all connected.
rivkamakAsked:
Who is Participating?
 
Anthony PerkinsConnect With a Mentor Commented:
Something like this will display all the errors triggered when trying to connect:
Dim ADOErrors, ADOError

Set myConn = Server.CreateObject("ADODB.Connection")
On Error Resume Next
myConn.open MM_donorSelect_app1
Set ADOErrors = myConn.Errors
On Error GoTo 0

If ADOErrors.Count = 0
	If myConn.State = 1 then 
		Response.write("First app is working")
		stringUse = MM_donorSelect_app1
		openConnection = true
	End If
Else
	For Each ADOError In ADOErrors
		Response.write "Error Number:" & ADOError.Number
		Response.write "Description:" & ADOError.Description
		Response.write "Source:" & ADOError.Source
		Response.write "SQLState:" & ADOError.SQLState
		Response.write "NativeError:" & ADOError.NativeError
		Response.write "Error Number:" & ADOError.Number
	Next		
End If

Open in new window

0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
in your catch have you tried using the following error type?

catch (SQLException ex)
{

{
0
 
rivkamakAuthor Commented:
This is my current script in ASp.
Where would I add that?

set myConn = Server.CreateObject("ADODB.Connection")
myConn.open MM_donorSelect_app1
 if myConn.State = 1 then 
 response.write("First app is working")
stringUse = MM_donorSelect_app1
openConnection = true

end if

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
Since you are using vbscript, you would need to use OnError

I am not sure you get the same opportunity to catch the error in classic ASP like that.
0
 
rivkamakAuthor Commented:
Any other ideas?
0
 
rivkamakAuthor Commented:
Can you explain what happens when the user hits the error like login failed?
Will they get a MSSQL error, or will they just a response.write?

Can I just remove the response.write section and put  a nice message like: You are unable to connect right now, please try again tommorow"
0
 
Anthony PerkinsCommented:
>>Can you explain what happens when the user hits the error like login failed?<<
Error message(s) will be displayed.  Note: There could be more than one error message.
>>Will they get a MSSQL error, or will they just a response.write?<<
Both.
>>Can I just remove the response.write section and put  a nice message like: You are unable to connect right now, please try again tommorow" <<
Of course.  I am merely gave you the code so that you could produce custom messages in each case.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.