Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class Form1
Dim serverstring As String = "server=....;user id=.....;password=.....;database=.....;"
Dim sqlconnection As MySqlConnection = New MySqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sqlconnection.ConnectionString = serverstring
Try
If sqlconnection.State = ConnectionState.Closed Then
sqlconnection.Open()
MsgBox("เชื่อมต่อสำเร็จ")
Else
sqlconnection.Close()
End If
Catch ex As Exception
MessageBox.Show("Error : " & ex.Message & "")
End
End Try
End Sub
this code this can use only Localhost, but how can I do if I want to connect to another Host online, Who know ..help me please
解决方案Really the only thing you need to change is the 'server=' part to the [IP/DomainName] and possibly specify a port. The other issue would be allowing a connection to the MySQL server through the firewall. Port 3306 is the default port for MySQL.
MySQL Connection Strings