Connecting to Oracle Database through Excel

Jimenemex picture Jimenemex · Jan 10, 2018 · Viewed 23.6k times · Source

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

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

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

New Query Wizard

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

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 PATH variable (32-bit first), and I also included a specific ORACLE_HOME and TNS_ADMIN to point to my 32-bit installation since my excel is 32-bit.

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

EDIT

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

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 Connection wizard, I know get this: enter image description here

Any Ideas?

Answer

Wernfried Domscheit picture Wernfried Domscheit · Jan 11, 2018

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

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

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 PATH regarding %ORACLE_HOME% and/or %ORACLE_HOME%\bin folder

Long version:

Your Excel is 32bit, so in general you did the right approach by putting the 32bit Client into PATH and 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.

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)

ODBC

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

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 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.

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)

Others

Oracle provides also the ODP.NET, Managed Driver which 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.

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.