我用mysql odbc 3.51 驱动VB就能连接上,用mysql odbc 5.1这个驱动连接调试就报错,为啥呢?
我用mysqlodbc3.51驱动VB就能连接上,用mysqlodbc5.1这个驱动连接调试VB就挂了,为啥呢?代码如下:OptionExplicitPublicCarC...
我用mysql odbc 3.51 驱动VB就能连接上,用mysql odbc 5.1这个驱动连接调试VB就挂了,为啥呢?代码如下:
Option Explicit
Public CarConn As New ADODB.Connection '标记参数数据库连接对象
Public serverIP As String
Public serverPort As String
Public DataBaseName As String
Public User As String
Public password As String
Public IsCntsql As Boolean '判断是否连接上数据库
Sub Main()
Call CntSQL
If IsCntsql = True Then
frmLogin.Show
End If
End Sub
Public Sub CntSQL() '连接数据库
Dim Filename As String
Filename = GetFile("Config.ini")
If Dir(Filename) = "" Then '文件不存在时,先创建ini文件
Open Filename For Append As #1
WriteIniStr "ServerConfig", "serverIP", "127.0.0.1"
WriteIniStr "ServerConfig", "serverPort", "3306"
WriteIniStr "ServerConfig", "DataBaseName", "CarManage"
WriteIniStr "ServerConfig", "User", "root"
WriteIniStr "ServerConfig", "Password", "admin"
Close #1
End If
serverIP = GetIniStr("ServerConfig", "serverIP")
serverPort = GetIniStr("ServerConfig", "serverPort")
DataBaseName = GetIniStr("ServerConfig", "DataBaseName")
User = GetIniStr("ServerConfig", "User")
password = GetIniStr("ServerConfig", "password")
On Error Resume Next
Dim Mysqlconn As String
Mysqlconn = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + Trim(serverIP) + ";PORT=" + Trim(serverPort) + ";DATABASE=" + Trim(DataBaseName) + ";USER=" + Trim(User) + ";PASSWORD=" + Trim(password) + ";OPTION=3;"
CarConn.Open Mysqlconn
If (Not (CarConn.State = adStateOpen)) Then
MsgBox "数据库连接错误,请确定网络设置正确,或联系网管中心", vbOKOnly + vbExclamation, "操作提示"
IsCntsql = False
frmNetSet.Show
Exit Sub
Else
IsCntsql = True
End If
End Sub
就是运行VB就挂了。 展开
Option Explicit
Public CarConn As New ADODB.Connection '标记参数数据库连接对象
Public serverIP As String
Public serverPort As String
Public DataBaseName As String
Public User As String
Public password As String
Public IsCntsql As Boolean '判断是否连接上数据库
Sub Main()
Call CntSQL
If IsCntsql = True Then
frmLogin.Show
End If
End Sub
Public Sub CntSQL() '连接数据库
Dim Filename As String
Filename = GetFile("Config.ini")
If Dir(Filename) = "" Then '文件不存在时,先创建ini文件
Open Filename For Append As #1
WriteIniStr "ServerConfig", "serverIP", "127.0.0.1"
WriteIniStr "ServerConfig", "serverPort", "3306"
WriteIniStr "ServerConfig", "DataBaseName", "CarManage"
WriteIniStr "ServerConfig", "User", "root"
WriteIniStr "ServerConfig", "Password", "admin"
Close #1
End If
serverIP = GetIniStr("ServerConfig", "serverIP")
serverPort = GetIniStr("ServerConfig", "serverPort")
DataBaseName = GetIniStr("ServerConfig", "DataBaseName")
User = GetIniStr("ServerConfig", "User")
password = GetIniStr("ServerConfig", "password")
On Error Resume Next
Dim Mysqlconn As String
Mysqlconn = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + Trim(serverIP) + ";PORT=" + Trim(serverPort) + ";DATABASE=" + Trim(DataBaseName) + ";USER=" + Trim(User) + ";PASSWORD=" + Trim(password) + ";OPTION=3;"
CarConn.Open Mysqlconn
If (Not (CarConn.State = adStateOpen)) Then
MsgBox "数据库连接错误,请确定网络设置正确,或联系网管中心", vbOKOnly + vbExclamation, "操作提示"
IsCntsql = False
frmNetSet.Show
Exit Sub
Else
IsCntsql = True
End If
End Sub
就是运行VB就挂了。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询