简体   繁体   English

MySQL与vbnet的远程连接

[英]mysql Remote Connection with vbnet

I get this error: " Reading from the stream has failed." 我收到此错误:“从流读取失败。”

Below is my code: 下面是我的代码:

Imports MySql.Data.MySqlClient

Public Class Form1
    Dim dbds As New DataSet
    Dim MySQLconn As New MySqlConnection
    Dim SQLda As New MySqlDataAdapter
    Dim cmd As MySqlCommand

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    MySQLconn = New MySqlConnection("server=www.address.com;User Id=user_nem;pwd=***;port=2082;database=db_db_db")


    Try
        MySQLconn.Open()
        MsgBox("Sucess, press ok to continue…", vbOKOnly)
         cmd.CommandText=(("set net_write_timeout=99999; set net_read_timeout=99999"), MySQLconn)
        cmd.ExecuteNonQuery()
        SQLda = New MySqlDataAdapter(("SELECT * FROM log_in"), MySQLconn)
        SQLda.Fill(dbds, "doctors")
        DataGridView1.DataSource = dbds.Tables("doctors")

    Catch ex As Exception
        MsgBox(Err.Description)
    End Try

End Sub

End Class

This code works fine with my localhost. 这段代码可以在我的本地主机上正常工作。 Any help will be appreciated.Thanks. 任何帮助将不胜感激。

i guess the mysql user user_nem has only access to the database via localhost. 我猜mysql用户user_nem只能通过本地主机访问数据库。

try creating a user like this 尝试创建这样的用户

GRANT ALL PRIVILEGES ON yourDbName.* To 'myuser'@'%' IDENTIFIED BY 'password';

the 'myuser'@'%' means the user with name myuser from any % location. 'myuser'@'%'表示来自任何%位置的名称为myuser的用户。 (dont forget to update that username in your connection string) (不要忘记更新您的连接字符串中的用户名)

I guess now its something like 'user_nem'@'localhost' or 'user_nem'@'127.0.0.1' thats why it works in local, but not in remote. 我现在猜想它像'user_nem'@'localhost''user_nem'@'127.0.0.1'这就是为什么它在本地而不是在远程工作的原因。

Try checking for firewalls also. 也尝试检查防火墙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM