大佬教程收集整理的这篇文章主要介绍了Excel VBA使用InstantClient连接到远程Oracle DB,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
最终编辑/使用了此功能(不使用驱动程序/提供程序:InstantClIEnt
,但仍使用文件):
Function ORAquery(strHost As String, strDatabase As String, strsql As String, strUser As String, strpassword As String)
Dim strConOracle, oConOracle, oRsOracle
Dim StrResult As String
StrResult = ""
strConOracle = "Driver={Microsoft ODBC for OraclE}; " & _
"CONNECTStriNG=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCol=TCp)" & _
"(HOST=" & strHost & ")(PORT=1521))" & _
"(CONNECT_DATA=(service_name=" & strDatabase & "))); uID=" & strUser & " ;pwd=" & strpassword & ";"
Set oConOracle = CreateObject("ADODB.Connection")
Set oRsOracle = CreateObject("ADODB.Recordset")
oConOracle.Open strConOracle
Set oRsOracle = oConOracle.Execute(strsql)
MsgBox (oRsOracle.FIElds(0).value)
varResult = oRsOracle.GetRows
do while Not oRsOracle.EOF
If StrResult <> "" Then
StrResult = StrResult & chr(10) & oRsOracle.FIElds(0).Value
Else
StrResult = oRsOracle.FIElds(0).Value
End If
oRsOracle.R_142_11845@oveNext
Loop
oConOracle.Close
Set oRsOracle = nothing
Set oConOracle = nothing
ORAquery = StrResult
End Function
Correct full Connection String:
Driver={Microsoft ODBC for OraclE}; CONNECTStriNG=(DESCRIPTION=(ADDRESS=(PROTOCol=TCp)(HOST=strHost)(PORT=1521))(CONNECT_DATA=(service_name=strDatabasE))); uID=strUser; pwd=strpassword;
ProvIDer or Driver:
需要设置PATH环境变量以指向InstantClIEnt。 没有使用任何其他环境变量,例如Oracle_HOME, TNS_@R_164_6739@。
我正在尝试使用Excel(主要是2003,以提高用户兼容性)连接
到远程Oracle DB。我想运行一个.sql脚本并将
数据集返回到工作表。
我在Windows 7 64位计算机上。我不知道Oracle DB
服务器的规格。
我想使它尽可能轻巧(
在客户端计算机上没有额外的文件安装,请尽可能将共享的网络位置用于所需的
文件)
迄今为止:
我从Oracle(
将32位和64位版本分别为12.1和11.2)下载并“安装”了InstantClient,并将其安装到了远程网络位置。
我尝试使用sqL Plus连接到Oracle DB,并且运行良好(我尝试
了几个已安装的InstantClient版本,以查看是否存在任何
兼容性问题)。
作为测试:在VBA中使用sqL Plus和SHell函数,我能够
成功地将数据假脱机到单独的excel文件中。
我使用各种
驱动程序/提供程序尝试了几种不同的连接字符串格式:
我收到的错误:
"Run-time error '-2147467259 (80004005)':
[Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed
The Oracle(tm) client and networking components were not found. these components are supplied by Oracle Corporation..."
"Run-time error '-2147467259 (80004005)':
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
"Run-time error '3706':
Provider cAnnot be found. It may not be properly installed"
和其他一些类似的错误。
我已经将包含InstantClient文件的网络位置添加到
PATH环境变量中。不知道我还
需要其他哪些环境变量,或者即使我当前的环境变量正确,也不确定。
我需要:
TNS_ADMIN吗?OracLE_HOME?
以上是大佬教程为你收集整理的Excel VBA使用InstantClient连接到远程Oracle DB全部内容,希望文章能够帮你解决Excel VBA使用InstantClient连接到远程Oracle DB所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。