我希望使用Excel VBA通过odbc连接Oracle数据库, 但是它不起作用,我之前在系统数据源名称中设置了ODBC数据源,并且测试连接正常工作!
VBA代码:
Sub GetData()
Dim conn As New ADODB.connection
Dim connString
connString = "DSN=HR;Uid=HR;Pwd=HR"
Dim rsRecords As New ADODB.Recordset
conn.Open connString
rsRecords.CursorLocation = adUseClient
rsRecords.Open "select * from GOLDLOT", conn, adOpenForwardOnly, adLockReadOnly
If conn.State = adStateOpen Then
MsgBox rsRecords.recordCount
Else
MsgBox "no connection"
End If
rsRecords.Close
Set rsRecords = Nothing
conn.Close
Set conn = Nothing
End Sub
执行代码结果时
运行时错误' -2147467259(80040e37)'
自动化错误
喜欢这个图片
我第一次使用VBA,请帮帮我。 THX。