4 Replies - 768 Views - Last Post: 02 November 2011 - 12:37 PM Rate Topic: -----

#1 keyplayer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-November 11

MySQL Connection Issue

Posted 01 November 2011 - 06:58 AM

I had a problem on this vb code. no problem when I run the program but did not come out the form but it produces a problem like this .. "Unable to connect to any of the specified MySQL hosts" ..I have a problem with conn.open ()

please explain what problems I had ... thank you ..

this my coding ..

Imports MySql.Data.MySqlClient
Imports System.Data
Public Class student_register
    Dim conn As New MySqlConnection
    Dim myCommand As New MySqlCommand
    Dim reader As MySqlDataReader
    Dim myConnString As String
    Dim probs, probsz As Integer

    Private Sub student_register_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        myConnString = "server=127.0.0.1" _
                & "user id=root;" _
                & "password=;" _
                & "database=xresult"
        conn.ConnectionString = myConnString
        comboBox1.Items.Clear()

        conn.Open()

        comboBox1.Items.Clear()
        myCommand.Connection = conn
        myCommand.CommandText = "SELECT * FROM kursus"
        reader = myCommand.ExecuteReader()

        While (reader.Read())
            comboBox1.Items.Add(New subjeckinfo1(reader.GetString(1), reader.GetString(0)))
        End While
        conn.Close()
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: MySQL Connection Issue

#2 Tryparse   User is offline

  • D.I.C Head
  • member icon

Reputation: 80
  • View blog
  • Posts: 193
  • Joined: 20-April 10

Re: MySQL Connection Issue

Posted 01 November 2011 - 07:16 AM

Usually when you get an error like that, there's either a problem with your connection string, or the database itself. In this case, there's no semicolon after your server or database (in your connection string). Add those in and see what happens.
Was This Post Helpful? 0
  • +
  • -

#3 keyplayer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-November 11

Re: MySQL Connection Issue

Posted 02 November 2011 - 12:11 PM

where i should put that code?? i newbie about this... :whistling: anyway thank u for help
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: MySQL Connection Issue

Posted 02 November 2011 - 12:18 PM

If Tryparse is saying what I think he is, do this:
myconnstring = "server=127.0.0.1;" & <the rest of your values>


You could also try getting rid of "server=<>". Why not just the IP? Ie instead of
"Server=127.0.0.1;"
Try this:
"127.0.0.1:"

J-Bo
Was This Post Helpful? 0
  • +
  • -

#5 Tryparse   User is offline

  • D.I.C Head
  • member icon

Reputation: 80
  • View blog
  • Posts: 193
  • Joined: 20-April 10

Re: MySQL Connection Issue

Posted 02 November 2011 - 12:37 PM

is correct. In full, what you're probably looking for is:
myConnString = "server=127.0.0.1;" _
                & "user id=root;" _
                & "password=;" _
                & "database=xresult;"

For more help with connection strings, you can check out connectionstrings.com
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1