M
Marcus
I have a function that simply returns TRUE if it can connect to a
particular Sql Server 2005 express, or FALSE if it cannot. I am getting
some strange error codes returned when the computer that sql server
resides on is not reachable. The error is different depending on the
connection string that I use. If I use the following connection string:
"server=192.1.1.1; Initial Catalog=master; uid=The_User;
password=The_Password; Connect Timeout = 10"
then the error number I get for the sqlexception caught is 53. If I add
'tcp:' in front of the IP address in the connection string like this:
"server=tcp:192.1.1.1; Initial Catalog=master; uid=The_User;
password=The_Password; Connect Timeout = 10"
then the error number I get for the sqlexception is 10060. If I add an
instance to the server in the connection string like this:
"server=192.1.1.1\SQLEXPRESS; Initial Catalog=master; uid=The_User;
password=The_Password; Connect Timeout = 10"
then I get the error number -1 for the SqlException.
I cannot find any reference to any of these error codes. Why is this
even being caught as a SqlException if it cannot even connect to the
Sql Server in the first place? Aren't the error numbers for
SqlException supposed to come from the master..sys.messages table???
Also, the timeout value seems to have no effect for the first two
connection strings above, with it taking usually around 30 seconds for
the exception to be caught.
I am confused...!
Here is the function I am using:
Public Function TestConnection() As Boolean
Dim myConnStr as string = "server=192.1.1.1; Initial
Catalog=master; uid=The_User; password=The_Password; Connect Timeout =
10"
Dim mySqlConn As new SqlConnection(myConnStr )
Try
mConn.Open()
Return True
Catch ex As SqlException
Debug.writeline(ex.tostring)
Debug.writeline("---------------- The error code was "
ex.number.tostring)
Return False
Catch ex As Exception
Return False
End Try
End Function
Thanks for any enlightenment.
Cheers,
Marcus
particular Sql Server 2005 express, or FALSE if it cannot. I am getting
some strange error codes returned when the computer that sql server
resides on is not reachable. The error is different depending on the
connection string that I use. If I use the following connection string:
"server=192.1.1.1; Initial Catalog=master; uid=The_User;
password=The_Password; Connect Timeout = 10"
then the error number I get for the sqlexception caught is 53. If I add
'tcp:' in front of the IP address in the connection string like this:
"server=tcp:192.1.1.1; Initial Catalog=master; uid=The_User;
password=The_Password; Connect Timeout = 10"
then the error number I get for the sqlexception is 10060. If I add an
instance to the server in the connection string like this:
"server=192.1.1.1\SQLEXPRESS; Initial Catalog=master; uid=The_User;
password=The_Password; Connect Timeout = 10"
then I get the error number -1 for the SqlException.
I cannot find any reference to any of these error codes. Why is this
even being caught as a SqlException if it cannot even connect to the
Sql Server in the first place? Aren't the error numbers for
SqlException supposed to come from the master..sys.messages table???
Also, the timeout value seems to have no effect for the first two
connection strings above, with it taking usually around 30 seconds for
the exception to be caught.
I am confused...!
Here is the function I am using:
Public Function TestConnection() As Boolean
Dim myConnStr as string = "server=192.1.1.1; Initial
Catalog=master; uid=The_User; password=The_Password; Connect Timeout =
10"
Dim mySqlConn As new SqlConnection(myConnStr )
Try
mConn.Open()
Return True
Catch ex As SqlException
Debug.writeline(ex.tostring)
Debug.writeline("---------------- The error code was "
ex.number.tostring)
Return False
Catch ex As Exception
Return False
End Try
End Function
Thanks for any enlightenment.
Cheers,
Marcus