M
mikster22
Guest
From the error message it suggests you can specify more than one host, i know why i am getting this problem, its because im currently running it in my design environment, which is in the same network as the server, and my router does not support nat loopback, however it does not always work remotely, this is for various reasons, but i have multiple MYSQL servers, and they are located at different domains. when debugging my program locally i get the following error message.
An unhandled exception of type MySql.Data.MySqlClient.MySqlException occurred in MySql.Data.dll
Additional information: Unable to connect to any of the specified MySQL hosts.
here is my source code for the SQL connection sub, i have tried to allow it to connect to multiple servers using try catch, if and for statements
Private Sub sqlconn()
Dim servername(5) As String
servername(0) = "Server=primarydomain.com;User Id=user;Password=pass;Database=database"
servername(1) = "Server=secondarydomain.com;User Id=user;Password=pass;Database=database"
servername(2) = "Server=sqlserver1.secondarydomain.com;User Id=user;Password=pass;Database=database"
servername(3) = "Server=sqlserver2.secondarydomain.com;User Id=user;Password=pass;Database=database"
servername(4) = "Server=sqlserver3.secondarydomain.com;User Id=user;Password=pass;Database=database"
servername(5) = "Server=192.168.y.z;User Id=user;Password=pass;Database=database"
begin login
SQLConnection.ConnectionString = servername(0)
Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
MsgBox("SQl connection connected") remove this after debugging
Else
SQLConnection.Close()
MsgBox("connection closed")
End If
Catch ex As Exception
Dim i As Integer
For i = 1 To 5
SQLConnection.ConnectionString = servername(i)
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
MsgBox("SQl connection connected") remove this after debugging
Else
SQLConnection.Close()
MsgBox("connection closed")
End If
MsgBox(ex.ToString) catches any error mesages - IE not connected.
Next
MsgBox("Unable to connect to SQL Server, the Server may be offline or your fire wall may be blocking the connection.")
End Try
End Sub
but (at least in debug mode) this doesnt work, is there a way to not have to use the try, for and if statements, and to specify other SQL hosts, as the error message says ANY, suggesting it is possible to connect to others. this would be especially helpful with using this on the second form, as it would cut down a few lines of coding.
i presume the statement would look something like this, seperated by commas or semicolons?
servername(0) = "Server=primarydomain.com,secondarydomain.com;User Id=user;Password=pass;Database=database"
thanks,
Michael Booth
Continue reading...
An unhandled exception of type MySql.Data.MySqlClient.MySqlException occurred in MySql.Data.dll
Additional information: Unable to connect to any of the specified MySQL hosts.
here is my source code for the SQL connection sub, i have tried to allow it to connect to multiple servers using try catch, if and for statements
Private Sub sqlconn()
Dim servername(5) As String
servername(0) = "Server=primarydomain.com;User Id=user;Password=pass;Database=database"
servername(1) = "Server=secondarydomain.com;User Id=user;Password=pass;Database=database"
servername(2) = "Server=sqlserver1.secondarydomain.com;User Id=user;Password=pass;Database=database"
servername(3) = "Server=sqlserver2.secondarydomain.com;User Id=user;Password=pass;Database=database"
servername(4) = "Server=sqlserver3.secondarydomain.com;User Id=user;Password=pass;Database=database"
servername(5) = "Server=192.168.y.z;User Id=user;Password=pass;Database=database"
begin login
SQLConnection.ConnectionString = servername(0)
Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
MsgBox("SQl connection connected") remove this after debugging
Else
SQLConnection.Close()
MsgBox("connection closed")
End If
Catch ex As Exception
Dim i As Integer
For i = 1 To 5
SQLConnection.ConnectionString = servername(i)
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
MsgBox("SQl connection connected") remove this after debugging
Else
SQLConnection.Close()
MsgBox("connection closed")
End If
MsgBox(ex.ToString) catches any error mesages - IE not connected.
Next
MsgBox("Unable to connect to SQL Server, the Server may be offline or your fire wall may be blocking the connection.")
End Try
End Sub
but (at least in debug mode) this doesnt work, is there a way to not have to use the try, for and if statements, and to specify other SQL hosts, as the error message says ANY, suggesting it is possible to connect to others. this would be especially helpful with using this on the second form, as it would cut down a few lines of coding.
i presume the statement would look something like this, seperated by commas or semicolons?
servername(0) = "Server=primarydomain.com,secondarydomain.com;User Id=user;Password=pass;Database=database"
thanks,
Michael Booth
Continue reading...