excel VBA中调试
Dim cnn As New ADODB.Connection
Dim cnnstr As String, mydata As String
mydata = "Student" ‘数据库名
cnnstr = "Provider=SQLOLEDB.1;" _
& "User ID =sa;" _
& "Password=;" _
& "Data Source =(local);" _ ’注意本机上SQL SERVER不能用IP地址,用(local)代替本地IP,或计算机名
& "Initial Catalog=" & mydata
cnn.ConnectionString = cnnstr
On Error Resume Next
cnn.Open
On Error GoTo 0
If cnn.State = adStateOpen Then
MsgBox "OK!"
Else
MsgBox "FAIL!"
End If
Set cnn = Nothing