通过 Excel 连接 Oracle 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48196768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:29:52  来源:igfitidea点击:

Connecting to Oracle Database through Excel

databaseexceloracleoracle12cexcel-2016

提问by Jimenemex

I'm trying to connect to an Oracle Database on our server from an Excel sheet, but am having trouble understanding why.

我正在尝试从 Excel 工作表连接到我们服务器上的 Oracle 数据库,但我无法理解原因。

I currently have both32-bit and 64-bit Oracle 12c installed in different ORACLE_HOMEs and have a 32-bit installation of Excel on my 64-bit computer.

我目前在不同的s 中安装32 位和 64 位 Oracle 12c,ORACLE_HOME并且在我的 64 位计算机上安装了 32 位 Excel。

I'm trying to connect to an Oracle Database in Excel using the New Querywizard.

我正在尝试使用新建查询向导连接到 Excel 中的 Oracle 数据库。

New Query Wizard

新建查询向导

When I click From Oracle DatabaseI get the following error/message.

当我单击From Oracle Database 时,我收到以下错误/消息。

Error

错误

I can continue with my current provider, but when I actually try to connect to a database I get this:

我可以继续使用我当前的提供程序,但是当我实际尝试连接到数据库时,我得到了这个:

Error

错误

What I don't understand is why I'm getting this error when I have both 32-bit and 64-bit versions of Oracle 12c installed on my computer. Both are included on my PATHvariable (32-bit first), and I also included a specific ORACLE_HOMEand TNS_ADMINto point to my 32-bit installation since my excel is 32-bit.

我不明白的是,当我的计算机上同时安装了 32 位和 64 位版本的 Oracle 12c 时,为什么会出现此错误。两者都包含在我的PATH变量中(首先是 32 位),并且我还包含了一个特定的ORACLE_HOMETNS_ADMIN指向我的 32 位安装,因为我的 excel 是 32 位。

I really want the ability to query from the database through Excel, but this problem is confusing me to death.

我真的很想要通过Excel从数据库中查询的能力,但是这个问题把我搞得晕头转向。

EDIT

编辑

I've also just added the ODBC Driver from my Oracle home's into the ODBC Data Source Administrator Tool.

我还刚刚将 Oracle 主页中的 ODBC 驱动程序添加到 ODBC 数据源管理工具中。

enter image description here

在此处输入图片说明

It's currently able to connect from this tool.

它目前可以从这个工具连接。

enter image description here

在此处输入图片说明

But when I try to connect to going through the ODBC Connectionwizard, I know get this: enter image description here

但是当我尝试通过ODBC 连接向导进行连接时,我知道得到这个: 在此处输入图片说明

Any Ideas?

有任何想法吗?

采纳答案by Wernfried Domscheit

How did you install 32bit and 64bit Oracle Client?

您是如何安装 32 位和 64 位 Oracle 客户端的?

Please have a look at this instruction: BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed

请看一下这个指令:BadImageFormatException。在安装了 32 位 Oracle 客户端组件的情况下以 64 位模式运行时会发生这种情况

Short version:

精简版:

Your excel is 32bit and you try to use the 32bit Oracle. I assume you launch the 64bit version of "ODBC Administrator" - there might be the mismatch. Or you have a problem in your PATHregarding %ORACLE_HOME%and/or %ORACLE_HOME%\binfolder

您的 excel 是 32 位的,而您尝试使用 32 位的 Oracle。我假设您启动了 64 位版本的“ODBC 管理员” - 可能存在不匹配。或者您的PATH关注%ORACLE_HOME%和/或%ORACLE_HOME%\bin文件夹有问题

Long version:

长版:

Your Excel is 32bit, so in general you did the right approach by putting the 32bit Client into PATHand for ORACLE_HOME, you cannot mix 32bit and 64bit assemblies in one process. Btw, when you follow the instructions above your Windows will manage this automatically.

您的 Excel 是 32 位的,因此一般而言,您通过将 32 位客户端放入PATH并为做正确的方法ORACLE_HOME,您不能在一个进程中混合 32 位和 64 位程序集。顺便说一句,当您按照上面的说明进行操作时,您的 Windows 将自动进行管理。

I assume you installed the Oracle Instant Client. The default Instant Client does not include neither any ODBC driver nor Oracle Data Provider (ODP.NET, Oracle.DataAccess.Client)

我假设您安装了 Oracle Instant Client。默认的 Instant Client 既不包含任何 ODBC 驱动程序,也不包含 Oracle Data Provider (ODP.NET, Oracle.DataAccess.Client)

ODBC

ODBC

You may have 2 ODBC drivers, one from Oracle typically called like Oracle in OraClient12_home1and one from Microsoft called Microsoft ODBC for Oracle(which should be installed by default Windows installation, however it also requires an Oracle Client).

您可能有 2 个 ODBC 驱动程序,一个来自 Oracle,通常在 OraClient12_home1 中称为Oracle,另一个来自 Microsoft,称为Microsoft ODBC for Oracle(默认情况下应该安装 Windows 安装,但它也需要一个 Oracle 客户端)。

The ODBC driver from Oracle is available for 32bit and 64bit, the Microsoft driver exits only for 32bit. You have 2 ODBC Administrators, 32bit (run c:\Windows\SysWOW64\odbcad32.exe) and 64bit (run c:\Windows\System32\odbcad32.exe). There you should see installed drivers for 32 resp. 64bit.

Oracle 的 ODBC 驱动程序可用于 32 位和 64 位,Microsoft 驱动程序仅适用于 32 位。您有 2 个 ODBC 管理员,32 位(运行c:\Windows\SysWOW64\odbcad32.exe)和 64 位(运行c:\Windows\System32\odbcad32.exe)。在那里,您应该看到已安装的 32 个驱动程序。64 位。

Oracle Data Provider

甲骨文数据提供者

For the Data Provider you have similar situation. You have one from Microsoft (Microsoft .NET Framework Data Provider for Oracle, System.Data.OracleClient) and from Oracle (Oracle Data Provider for .NET, Oracle.DataAccess.Client, several versions). Both are available for 32bit and 64bit.

对于数据提供者,您有类似的情况。你有一个从Microsoft(微软.NET Framework数据提供程序的OracleSystem.Data.OracleClient)和甲骨文(Oracle数据提供程序.NETOracle.DataAccess.Client几个版本)。两者都可用于 32 位和 64 位。

In principle it does not matter which driver/provider you use to connect to Oracle - just the architecture (i.e. 32 vs. 64 bit) has to match. Each driver/provider requires according Oracle Client installation. All drivers/providers from Microsoft have been deprecated, you should prefer the Oracle ones (as stated in the warning message)

原则上,您使用哪个驱动程序/提供商连接到 Oracle 并不重要——只是架构(即 32 位与 64 位)必须匹配。每个驱动程序/提供程序都需要根据 Oracle 客户端安装。Microsoft 的所有驱动程序/提供程序都已弃用,您应该更喜欢 Oracle 驱动程序(如警告消息中所述)

Others

其他

Oracle provides also the ODP.NET, Managed Driverwhich does not require any further Oracle Client installation and runs on both, 32bit and 64bit. However, I don't know whether you can use this in Excel.

Oracle 还提供ODP.NET 托管驱动程序,它不需要任何进一步的 Oracle 客户端安装并且可以在 32 位和 64 位上运行。但是,我不知道您是否可以在Excel中使用它。

Last but not least, you also have OLE DB provider. Again one from Microsoft (Microsoft OLE DB Provider for Oracle) and one from Oracle (Oracle Provider for OLE DB). The Microsoft provider exist only for 32bit and has been deprecated.

最后但并非最不重要的是,您还有 OLE DB 提供程序。一个来自 Microsoft(Microsoft OLE DB Provider for Oracle)和一个来自 Oracle(Oracle Provider for OLE DB)。Microsoft 提供程序仅适用于 32 位并且已被弃用。