我想连接mysql phpmyadmin数据库并在我的应用程序中获取数据在vb.net但我无法连接。我收到无法与指定主机连接的错误消息。 当我在浏览器中输入10.1.1.53/phpmyadmin时,我能够打开我的所有数据库,没有任何密码或用户名,但当我尝试通过单击按钮连接我的vb.net应用程序时,我收到了错误消息。 这是我的代码。请帮帮我。
ImportsMySql.Data.MySqlClient
PublicClasslogin
Dim con AsMySqlConnection
Dim reader AsMySqlDataReader
Dim command AsMySqlCommand
DimmyconAsString = "server=10.1.1.53/phpmyadmin;database=dbtest"
PrivateSubbtnlogin_Click(sender AsObject, e AsEventArgs) Handlesbtnlogin.Click
login()
EndSub
PrivateSublogin()
con = NewMySqlConnection
con.ConnectionString = mycon
Try
con.Open()
Catch ex As Exception
EndTry
EndSub
PrivateSubbtnexit_Click(sender AsObject, e AsEventArgs) Handlesbtnexit.Click
Me.Close()
EndSub
EndClass
答案 0 :(得分:0)
Public Sub login()
Dim DatabaseName As String = "dbtest"
Dim server As String = "10.1.1.53"
Dim userName As String = "username"
Dim password1 As String = "pass"
If Not conn Is Nothing Then conn.Close()
conn.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password1, DatabaseName)
Try
conn.Open()
' MsgBox("Connected")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'conn.Close()
End Sub
你给我的那个是DimmyconAsString<<那是错字吗?