我在VB.NET中开发了一个项目mysql使用vb.net?
在这个项目中我想使用驻留在我的WEB服务器上的MySQL数据。
我可以与我的本地主机的MySQL服务器通信,但不能与WEB服务器通信。
在我的cPanel我添加主机从远程数据库访问
但我不能与WEB的MySQL服务器进行通信。
请帮帮我。
Dim connection As MySqlConnection
connection = New MySqlConnection()
connection.ConnectionString = "Server=saver ip; Port=2082; Uid=username; Pwd=password; Database=database; Connect Timeout=60;"
Try
connection.Open()
MessageBox.Show("Connection Opened Successfully")
connection.Close()
Catch mysql_error As MySqlException
MessageBox.Show("Error Connecting to Database: " & mysql_error.Message)
Finally
connection.Dispose()
End Try
当我尝试运行这个。我得到了这个错误“错误连接到数据库:从流中读取失败。”
注意*:我的数据库名称如“myweb_dbname”和我的用户名“myweb_username”是这样可以吗?我正在使用cPanal1.0(RC1)和mysql5.1.56-log和os linux。
Jeff V:谢谢!当我尝试你的代码..
Dim dataConnection As New MySql.Data.MySqlClient.MySqlConnection()
dataConnection.ConnectionString = "Server = xx.xx.xxx.xxx; Database = dbNAME; Uid = userID; Pwd = password;"
Dim dataCommand As MySql.Data.MySqlClient.MySqlCommand = New MySqlCommand()
dataCommand.Connection = dataConnection
Try
dataConnection.Open()
dataConnection.Close()
Catch x As Exception
Console.WriteLine(x.Message.ToString())
MsgBox(x.ToString)
End Try
我收到此错误信息:
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at mysql.Form1.Button3_Click(Object sender, EventArgs e) in C:\Users\pram\Documents\Visual Studio 2008\Projects\mysql\mysql\Form1.vb:line 48
在48行 “dataConnection.Open()”
我有一个从.NET ......会谈到一个MySQL数据库代码,但它是在家里。如果今晚你没有得到合适的答案,我会找到并发布。 – webdad3 2012-02-21 17:24:18
谢谢!非常! @JeffV – pram 2012-02-21 17:37:34
仍然没有工作的答案plz ....帮我...有人吗? – pram 2012-02-22 13:11:16