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