怎么处理excel vba连接局域网中电脑上的mysql数据库

MySql 码拜 8年前 (2016-02-02) 1549次浏览
本人想用excel vba和mysql数据库做一个小型数据平台,让局域网中的全部人通过exce访问同一台电脑上的mysql数据.
下列程序在本机上能运行,在其他机子上不能运行.
Private Sub CommandButton1_Click()
Dim strconnt As String
Dim strSql  As String

strconnt = “”
Set connt = New ADODB.Connection
Set rs = New ADODB.Recordset
Dim sevip, Db, user, pwd As String
“”设服务器地址、所连数据,及登录用户密码
sevip = “127.0.0.1”
Db = “pzx”
user = “root”
pwd = “13678096166”
strconnt = “DRIVER={MySql ODBC 5.3 Unicode Driver};SERVER=” & sevip & “;Database=” & Db & “;Uid=” & user & “;Pwd=” & pwd & “;Stmt=set names GBK”
connt.ConnectionString = strconnt
connt.Open
strSql = “select * from info”
rs.Open strSql, connt, 1, 1
Sheets(“sheet1”).Range(“a1”).CopyFromRecordset rs
rs.Close
connt.Close
End Sub
本人的机子在局域网中用固定IP:192.168.0.102 ,当把服务器地址换成192.168.0.102 时,在本机不能运行.
Private Sub CommandButton1_Click()
Dim strconnt As String
Dim strSql  As String

strconnt = “”
Set connt = New ADODB.Connection
Set rs = New ADODB.Recordset
Dim sevip, Db, user, pwd As String
“”设服务器地址、所连数据,及登录用户密码
sevip = “192.168.0.102”
Db = “pzx”
user = “root”
pwd = “13678096166”
strconnt = “DRIVER={MySql ODBC 5.3 Unicode Driver};SERVER=” & sevip & “;Database=” & Db & “;Uid=” & user & “;Pwd=” & pwd & “;Stmt=set names GBK”
connt.ConnectionString = strconnt
connt.Open
strSql = “select * from info”
rs.Open strSql, connt, 1, 1
Sheets(“sheet1”).Range(“a1”).CopyFromRecordset rs
rs.Close
connt.Close
End Sub
问一下怎么实现上述访问功能?

解决方案:30分
你可以登录ip地址为192.168.0.102的数据库?用ip登录。怀疑是你没有开启数据库的连接权限,阻止了其他ip的连接
解决方案:10分
错误信息是什么?

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么处理excel vba连接局域网中电脑上的mysql数据库
喜欢 (0)
[1034331897@qq.com]
分享 (0)