任何人都知道如何将 vb.net windows 窗体应用程序连接到在线/内联网数据库?
我尝试使用 localhost,是的,它可以连接,但是如果我在主机中使用 IP,我将无法访问数据库。
这是我的连接:
Dim conStr As String = "server=192.168.1.18;Uid=root;Pwd='';Database=hrms"
Dim con As New MySqlConnection(conStr)
Try
MessageBox.Show("Connecting to mysql database..................")
con.Open()
Dim sqlStr As String = "SELECT * FROM accounts"
Dim cmd As MySqlCommand = New MySqlCommand(sqlStr, con)
Dim rd As MySqlDataReader = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
MessageBox.Show(rd(0) & " " & rd(1) & " Naa koi na fetch")
Exit Sub
Else
MessageBox.Show("Could not find something")
Exit Sub
End If
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try