Windows 7 (x64)、VB6.0 - SP6和MySQL 5.2 ODBC连接器和Xammp服务器
这在本地主机上正常工作,现在我正在尝试用相同的表连接远程MySQL数据库,但是成功连接后,它会给我运行时错误'-2147217865 (80040e37)‘,并说表MySQL不存在,但实际上它存在于我的数据库中。我在网上搜索了所有可能的解决方案,但它仍然对我没有用。
这里是我的连接字符串
Option Explicit
Public Function Connected2DB() As Boolean
Dim isOpen As Boolean
Dim ANS As VbMsgBoxResult
Dim dbpath As String
isOpen = False
On Error GoTo err
Do Until isOpen = True
CN.CursorLocation = adUseClient
CN.ConnectionString = "Provider=MSDASQL;Driver={MySQL ODBC 5.2 ANSI Driver};DSN=myDSN;Server=MyIPAddress;Database=myDatabase;Uid=DBUserName;Pwd=mypassword;Port=3306;"
CN.Open
isOpen = True
Loop
Connected2DB = isOpen
Exit Function
err:
ANS = MsgBox("Error Number: " & err.Number & vbCrLf & "Description: " & err.Description, _
vbCritical + vbRetryCancel)
If ANS = vbCancel Then
Connected2DB = False
ElseIf ANS = vbRetry Then
Connected2DB = vbRetry
End If
End Function
Public Sub CloseDB()
'Close the connection
CN.Close
Set CN = Nothing
End Sub这是我的密码
Private Sub cmdLogin_Click()
Dim strPass As String
If txtUsername.Text = "" Then
MsgBox "Username and/or Password is incorrect.Try Again!", vbExclamation
txtUsername.SetFocus
Exit Sub
End If
If txtPassword.Text = "" Then
MsgBox "Username and/or Password is incorrect.Try Again!", vbExclamation
txtPassword.SetFocus
Exit Sub
End If
strPass = Encode(txtPassword.Text)
'strPass = txtPassword.Text
Set RS = New ADODB.Recordset
'If RS.State = adStateOpen Then RS.Close
RS.Open "SELECT tblUsers.* FROM tblUsers WHERE Username='" & txtUsername.Text & "' AND Password ='" & strPass & "' AND StatusCD ='ACTIVE'", CN, adOpenStatic, adLockReadOnly
If RS.RecordCount < 1 Then
Attempt = Attempt - 1
MsgBox "Username and/or Password is incorrect.Try Again!", vbExclamation
lblAttempt.Caption = "Remaining Attempt(s): " & Attempt
If Attempt = 0 Then
MsgBox "You have reached maximum login attempts. System will now be terminated!", vbExclamation
MDIMain.CloseMe = True
END_APP = True
Unload Me
End If
Else
LOGIN_SUCCEEDED = True
ACTIVE_USER.USERID = RS.Fields("UserCD")
ACTIVE_USER.FULLNAME = RS.Fields("Fullname")
ACTIVE_USER.USERNAME = RS.Fields("Username")
ACTIVE_USER.PASSCODE = RS.Fields("Password")
ACTIVE_USER.USER_ISADMIN = CBool(changeYNValue(getValueAt("SELECT Username,IsAdmin FROM tblUsers WHERE Username='" & txtUsername.Text & "'", "IsAdmin")))
blnCreate = CBool(changeYNValue(RS.Fields("ModCreate")))
blnUpdate = CBool(changeYNValue(RS.Fields("ModUpdate")))
blnDelete = CBool(changeYNValue(RS.Fields("ModDelete")))
'InsertLogs Name, "Action Taken: Logged in to the Program", "Executed:" & Time
MDIMain.lblCurrentUser.Caption = ACTIVE_USER.FULLNAME
MDIMain.lblDate.Caption = Now() 'Format(Now, "MMMM dd, yyyy")
Unload Me
MDIMain.Show
End If
End Sub发布于 2017-02-10 07:58:28
远程服务器权限接受表名(区分大小写),然后在代码中对远程服务器上的表名进行双重检查。通过重命名所有相关表的MySQL语句来解决问题
https://stackoverflow.com/questions/40659757
复制相似问题