[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

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.
0
rivkamak
Asked:
rivkamak
  • 3
  • 2
  • 2
1 Solution
 
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
 
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
rivkamakAuthor Commented:
Any other ideas?
0
 
Anthony PerkinsCommented:
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
 
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

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now