Dim strSql As String
strSql = "DRIVER={Microsoft ODBC for Oracle};UID="
strSql = strSql & [user]Value & ";PWD="
strSql = strSql & [Password]Value & ";SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST="
strSql = strSql & [ip]Value
strSql = strSql & ")(PORT="
strSql = strSql & [port]Value
strSql = strSql & "))(CONNECT_DATA=(SID="
strSql = strSql & [sid]Value
strSql = strSql & ")));"
将中括号中的内容通过设定名称指定对应单元格即可。另外,一定得安装好ORACLE客户端才行。
Dim cn As New ADODBConnection '定义数据链接对象 ,保存连接数据库信息;请先添加ADO引用
Dim rs As New ADODBRecordset '定义记录集对象,保存数据表
Dim strCn As String, strSQL As String '字符串变量
Dim i As Integer, j As Integer, sht As Worksheet
strCn = "Provider=MSDAORA1;Password="psw";User ID="userid";Data Source="DB";Persist Security Info=True" strSQL = "select from tab"
cnOpen strCn
rsOpen strSQL, cn
xrow = 1
Do While (Not rsEOF)
Sheet1Cells(xrow, 1) = rsFields()Item(0)
xrow = xrow + 1
rs MoveNext
Loop
End Sub
以上就是关于vba 远程连接 Oracle 链接字符串全部的内容,包括:vba 远程连接 Oracle 链接字符串、EXCEL VBA 如何在不安装oracle客户端情况连接oracle服务器。、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)