excel連接mysql失敗的解決方法
當excel連接mysql失敗時可以在excel中添加以下代碼即可連接到MySQL。
Public Sub nckxr()
Dim cnn As ADODB.ConnectionDim cnnstr As String, mydata As String
mydata = "nckxr" '指定數據庫名稱
cnnstr = "providet=SQLoledb;" _
& "user id=sa;" _
& "password=111;" _
& "date source=ZBS3;" _
& "initial catalog=" & mydata
set cnn = new ADODB.Connectioncnn.connectionstring = cnnstr
On Error Resume Next
cnn.Open
On Error GoTo 0
If cnn.State = adstateopen Then
MsgBox "數據庫連接成功!", vbInformation, "連接數據庫"
Else
MsgBox "數據庫連接失敗!", vbInformation, "連接數據庫"
End If
Set cnn = Nothing
End Sub