当前位置:编程学习 > C#/ASP.NET >>

要怎么样才能连接远程mysql数据库呢-------急急急急

小弟做了一个小程序,需要连接到一台远程计算机上面的mysql数据库 mysql数据库那边已经设置了任意主机登录呀但是我点连接还是连接不上,测试连接本地的就可以 这是为何
代码如下
Imports System.IO
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports MySql.Data.MySqlClient
Public Class Form2

    Dim m_strConnection As String
    Dim myConn As MySqlConnection
    Dim conn As MySqlConnection
    Dim data As DataTable
    Dim da As MySqlDataAdapter
    Dim cb As MySqlCommandBuilder

    Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Form1.Visible = True
        Me.Dispose()
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim constr As String = "server=localhost;Port=3306;userid=root; password=goods1810;database=tsjy;pooling=false"
        ' 测试连接
        myConn = New MySqlConnection(constr)
        Try
            myConn.Open()
            MsgBox("数据库连接成功!")
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & "数据库连接失败!")
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim constr As String = "server=localhost;Port=3306;userid=root; password=goods1810;database=tsjy;pooling=false"
        ' 测试连接
        myConn = New MySqlConnection(constr)
        Try
            myConn.Open()
            MsgBox("数据库连接成功!")
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & "数据库连接失败!")
        End Try

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim temp_int, int_lrow, int_rrow As Integer

        data = New DataTable
        Try
            da = New MySqlDataAdapter("SELECT * FROM cjcx", myConn)            '在相关表中查找数据 db_table 为表名,name 为列名
            cb = New MySqlCommandBuilder(da)

            da.Fill(data)
            int_rrow = data.Rows.Count              '返回查找后的数据行数,返回0行则表示没有找到记录,返回大于0行,则表示找到了相关记录
            If int_rrow = 0 Then
                MessageBox.Show("无记录")
            Else
                MessageBox.Show(data.Rows.Item(0).Item(3).ToString)   'Item(0).Item(3) 表示返回的第1条记录(第一条的下标为0)中的第4列值
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub
End Class
如图上面所写的 我用本地的就库 写上ip就不行就算是127.0.0.1都不行怎么办呢 数据库 mysql vb.ent 计算机 --------------------编程问答-------------------- --------------------编程问答-------------------- 要中小妹,该多好,肯定会有更多人来回你的。

你将远程测试机器和你自己机器的windows防火墙全部关了,试试 --------------------编程问答-------------------- 嚓,我才发现服务器没开端口,晕死咯. --------------------编程问答-------------------- 中小妹是什么 --------------------编程问答-------------------- 要是小妹 ,打错字了
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,