0

Is there any difference in code besides the connection string when connecting to a MySQL db server from a MySQL db local on machine?

I want to use this against a MySQL db installed local on a machine. Can it work or do i need to apply changes?

Public Sub Foo()
    Try
        Dim result As String
        Dim conn As MySqlConnection
        conn = New MySqlConnection()

        Dim DatabaseName As String = ""
        Dim server As String = "db4free.net" 
        Dim port As String = "3306"
        Dim userName As String = ""
        Dim password As String = ""
        conn.ConnectionString = String.Format("server={0}; Port={1}; user id={2}; password={3}; database={4}; pooling=false", server, port, userName, password, DatabaseName)
        'conn.ConnectionString = "server=localhost; user id=root; password=xxxx; database=main"
        Try
            conn.Open()
            Console.WriteLine("OPEN CONN")
            Console.WriteLine()

        Catch myerror As MySqlException
            Console.WriteLine("Connection to the Database Failed")
        End Try
        Dim myAdapter As New MySqlDataAdapter
        Dim sqlquery = "SELECT * FROM `Customer`"
        Dim myCommand As New MySqlCommand()
        myCommand.Connection = conn
        myCommand.CommandText = sqlquery
        myAdapter.SelectCommand = myCommand
        Dim myData As MySqlDataReader
        myData = myCommand.ExecuteReader()
        Console.WriteLine("ID" & vbTab & "Name" & vbTab & "City" & vbTab & "Age")
        Console.WriteLine()
        While myData.Read()
            Console.WriteLine(myData("id").ToString & vbTab & myData("Name") & vbTab & myData("City") & vbTab & myData(3).ToString)
        End While        

    Catch ex As Exception
        Console.WriteLine(ex.Message)
    End Try


End Sub
Chornsyld
  • 25
  • 1
  • 1
  • 4
  • In local db normally the server is "localhost" – ScaisEdge Oct 10 '16 at 09:29
  • `string connString = @"server=localhost;userid=johnnyBoy;password=thePassword;database=theDb";` ... so, typo? – Drew Oct 10 '16 at 09:54
  • The above works for me. See link to version [Here](http://stackoverflow.com/a/38277659). client version 6.9.6 but now works fine on 6.9.9 ... The dupe target points to the mysql page, differing slightly – Drew Oct 10 '16 at 10:02
  • Yeah It works fine. Just a question about the local db. So all I need to do is change the connection string to localhost and it will work. Thanks. – Chornsyld Oct 10 '16 at 11:21

0 Answers0