我试图使用Excel (主要是2003,以获得更多的用户兼容性)连接到远程Oracle DB。我想运行一个.sql脚本并将数据集返回到工作表中。
我在一台Windows 7 64位机器上。我不知道Oracle DB服务器的规范。
我希望保持尽可能轻量级(在客户端机器上没有额外的文件安装,尽可能多地使用共享网络位置来处理所需的文件)。
迄今为止:
我从Oracle (32位和64位版本的12.1和11.2版本)下载并“安装”到远程网络位置。
我尝试使用SQL连接到Oracle,它运行良好(我尝试了几个已安装的InstantClient版本,以查看是否存在任何兼容性问题)。
作为一个测试:在VBA中使用SQL和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"还有其他一些类似的错误。
我已将包含实例化客户端文件的网络位置添加到PATH环境变量中。不确定我所需要的其他环境变量,或者即使我当前的环境变量是正确的。
我需要:
TNS_ADMIN?ORACLE_HOME?
问题:
- What is the correct _full_ connection string? (I used the EZConnect format with SQLPlus; are the actual connection details the same? and for clarification, could someone post an example of how the EZConnect format converts to the other format(s)?) 我的EZConnect格式:EZConnect
- What "provider" or "driver" _should_ I use for this purpose and are there any significant differences?- What environmental variables do I **require** to make this work?
我发现了很多类似或相关的问题,但没有一个问题能直接回答我的问题,或者帮助我完全解决这个问题。
发布于 2014-03-12 17:42:28
最后编辑/使用此函数(而不是(?)使用驱动程序/提供程序: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.MoveNext
Loop
oConOracle.Close
Set oRsOracle = Nothing
Set oConOracle = Nothing
ORAQUERY = StrResult
End Function正确的全连接字符串:
Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=strHost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=strDatabase))); uid=strUser; pwd=strPassword;提供者或驱动程序:
{Microsoft ODBC for Oracle}
需要设置PATH环境变量以指向实例化客户端。
没有使用任何其他环境变量,如ORACLE_HOME、TNS_ADMIN等。
https://stackoverflow.com/questions/22154288
复制相似问题