Questions

Connecting to MySQL from VB.net

Tags:
+
0 Votes
Locked

Connecting to MySQL from VB.net

jvoyles
I have been working on an application from my PC using MySQL and VB.net. When I run the application from the PC and include in the connection string the name of the server I need to connect to I can connect without any problems. When I move the application to the server to run from there I get the exception

"Unable to connect to any of the specified MySQL hosts."

At first I figured this was because I was trying to access the MySQL database from the server instead of my PC so I put 'localhost' in the connection string and I still get this error.

I am using Studio 2005 to build the application and I am fairly new to VB.net and MySQL. Teaching myself. When the application is done I will be wanting to run it from the server with the users running it over the network and our company VPN. Is there something special I need to do in my developement to accomodate this?

I have read all the documentation for MySQL that I thought might address this issue and haven't been able to come up with anything.

Any suggestions would be helpful. The server is a Novell version 6 server if that makes any difference.

Thanks for your help.
  • +
    0 Votes
    robo_dev

    http://blogs.ittoolbox.com/windows/alex/archives/getting-mono-and-mysql-to-play-nice-14516

    "Server=localhost;Database=test;User ID=test;Password=test;Pooling=false;Connection Timeout=10;Protocol=socket;Port=3306;"

    +
    0 Votes
    jvoyles

    I found the same article before I posted my question. I have tried that work around and it didn't work.

    Thanks for the link though.

    +
    0 Votes
    jvoyles

    It turned out that the exception was thrown because the server was not trusted by my .net framework. Once I made the local intranet trusted it worked.

    Now my question would be is this something that will be an issue for the users as they access the program over the network? If it is then is there a way to fix it programmatically so that I can set up an install or something to change the .net configuration, making it seamless for the user?

    Once again thanks for your help.

    +
    0 Votes
    hamm_x_s

    I have been developing applications using .net 2005 and MYSQL 5 (.net framework 2.0). I have never seen that kind of problem, even when connecting over a network. I simply use this connection string and I am done.

    uSE THE .NET CONNECTORS

    Dim myConnString As String
    myConnString = "server=" & cmbServer.Text & ";" & "user id=" & txtUser.Text & ";" & "password=" & txtPassword.Text & ";" & "database=" & cmbDatabases.Text & ";"
    conn.ConnectionString = myConnString
    Try
    conn.Open()
    conn.Close()
    MessageBox.Show("Permission Granted! Proceed to the system", "APPLICATION")
    Dim main As New frmMain
    main.connectionString = myConnString
    main.Show()
    Me.Hide()
    Me.Close()
    Catch ex As MySqlException
    MessageBox.Show("Connection Error! Check options and try again " & ex.Message, "HURMIS")
    Finally
    conn.Dispose()
    End Try

    +
    0 Votes
    jvoyles

    As it so often turns out with coding issues the issue isn't what we thought it was.

    My problem wasn't with the connection string after all. It was with the .net security levels on my system. Changing the security level for my local intranet from medium to full allowed me to access the data.

    I have since found documentation on how to set the permissions for and individual program so that I can leave the overall intranet settings at medium while I give one program full trust in the .net configuration.

    Thank you all so much though for the help you have provided.

    +
    0 Votes
    hamm_x_s

    The error you are getting seems to arise from the mysql server not being active.

    What connector are you using? Is it the ODBC connector or the .net connector. I encourage you to use the .net connector. It is very stable and I have not found any problem connecting from any point to another. The standard connection string is:

    Dim myConnString As String
    myConnString = "server=" & cmbServer.Text & ";" & "user id=" & txtUser.Text & ";" & "password=" & txtPassword.Text & ";" & "database=" & cmbDatabases.Text & ";"
    conn.ConnectionString = myConnString
    Try
    conn.Open()
    conn.Close()
    MessageBox.Show("Permission Granted!", "MyProgram")
    Catch ex As MySqlException
    MessageBox.Show("Connection Error!" & ex.Message, "HURMIS")
    Finally
    conn.Dispose()
    End Try
    You cant go wrong with this.

  • +
    0 Votes
    robo_dev

    http://blogs.ittoolbox.com/windows/alex/archives/getting-mono-and-mysql-to-play-nice-14516

    "Server=localhost;Database=test;User ID=test;Password=test;Pooling=false;Connection Timeout=10;Protocol=socket;Port=3306;"

    +
    0 Votes
    jvoyles

    I found the same article before I posted my question. I have tried that work around and it didn't work.

    Thanks for the link though.

    +
    0 Votes
    jvoyles

    It turned out that the exception was thrown because the server was not trusted by my .net framework. Once I made the local intranet trusted it worked.

    Now my question would be is this something that will be an issue for the users as they access the program over the network? If it is then is there a way to fix it programmatically so that I can set up an install or something to change the .net configuration, making it seamless for the user?

    Once again thanks for your help.

    +
    0 Votes
    hamm_x_s

    I have been developing applications using .net 2005 and MYSQL 5 (.net framework 2.0). I have never seen that kind of problem, even when connecting over a network. I simply use this connection string and I am done.

    uSE THE .NET CONNECTORS

    Dim myConnString As String
    myConnString = "server=" & cmbServer.Text & ";" & "user id=" & txtUser.Text & ";" & "password=" & txtPassword.Text & ";" & "database=" & cmbDatabases.Text & ";"
    conn.ConnectionString = myConnString
    Try
    conn.Open()
    conn.Close()
    MessageBox.Show("Permission Granted! Proceed to the system", "APPLICATION")
    Dim main As New frmMain
    main.connectionString = myConnString
    main.Show()
    Me.Hide()
    Me.Close()
    Catch ex As MySqlException
    MessageBox.Show("Connection Error! Check options and try again " & ex.Message, "HURMIS")
    Finally
    conn.Dispose()
    End Try

    +
    0 Votes
    jvoyles

    As it so often turns out with coding issues the issue isn't what we thought it was.

    My problem wasn't with the connection string after all. It was with the .net security levels on my system. Changing the security level for my local intranet from medium to full allowed me to access the data.

    I have since found documentation on how to set the permissions for and individual program so that I can leave the overall intranet settings at medium while I give one program full trust in the .net configuration.

    Thank you all so much though for the help you have provided.

    +
    0 Votes
    hamm_x_s

    The error you are getting seems to arise from the mysql server not being active.

    What connector are you using? Is it the ODBC connector or the .net connector. I encourage you to use the .net connector. It is very stable and I have not found any problem connecting from any point to another. The standard connection string is:

    Dim myConnString As String
    myConnString = "server=" & cmbServer.Text & ";" & "user id=" & txtUser.Text & ";" & "password=" & txtPassword.Text & ";" & "database=" & cmbDatabases.Text & ";"
    conn.ConnectionString = myConnString
    Try
    conn.Open()
    conn.Close()
    MessageBox.Show("Permission Granted!", "MyProgram")
    Catch ex As MySqlException
    MessageBox.Show("Connection Error!" & ex.Message, "HURMIS")
    Finally
    conn.Dispose()
    End Try
    You cant go wrong with this.