简体   繁体   中英

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.

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. (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.

Try checking for firewalls also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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