Excel Connect to Oracle 12c Using VBA - excel

Trying connect to an Oracle Database 12c Enterprise Edition 64-bit with Excel VBA.
The client machine has the following 32-bit drivers installed:
Microsoft ODBC for Oracle
Oracle in OraClient11g_home1
Oracle in OraClient12Home1_32bit
And the following 64-bit drivers installed:
Oracle in OraClient11g_home1
Oracle in OraClient12Home1
The file has the following reference:
Microsoft ActiveX Data Objects 6.1 Library
I've tried multiple formats of the connection string but nothing works.
'This gave the error "[Oracle][ODBC][Ora]ORA-12560: TNS:protocol adapter error"
cs = "Driver={Oracle in OraClient12Home1}; UID=myuid; PWD=mypwd; SERVER=myhostname/myservicename;"
'This gave the error "[Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve the connect identifier specified"
cs = "Driver={Oracle in OraClient12Home1}; UID=myuid; PWD=mypwd; SERVER=myhostname; DBQ=myservicename;"
'This gave the error "[Oracle][ODBC][Ora]ORA-12560: TNS:protocol adapter error"
cs = "Driver={Oracle in OraClient12Home1}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhostname)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=myservicename)));UID=myuid; PWD=mypwd;"
'This would crash Excel
cs = "Driver={Oracle in OraClient11g_home1}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhostname)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=myservicename)));UID=myuid; PWD=mypwd;"
I've also tried variations using the following drivers in the connection string
Microsoft ODBC for Oracle
OraOLEDB.Oracle
Oracle in OraClient12Home1

Thanks for your help everyone and sorry for the delayed response (had multiple work related "fires" I was putting out).
Anyway... I found a solution that worked for me. I don't think the problem was having multiple drivers on the same machine because I'm now able to connect without changing anything except the connection string method I used.
While I'm still not sure why the "driver" method of my connection string didn't work, I was able to use a "provider" based connection string and that worked.
'Using OraOLEDB.Oracle.1.
cs = "Provider=OraOLEDB.Oracle.1;User ID=myuid;Password=mypwd;Data Source=myhostname/myservicename;"
'Using OraOLEDB.Oracle.
cs = "Provider=OraOLEDB.Oracle;User ID=myuid;Password=mypwd;Data Source=myhostname/myservicename;"
'Using OraOLEDB.Oracle as a TNS-less connection string.
cs = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myhostname)(PORT=myport)))(CONNECT_DATA=(SERVICE_NAME=myservicename)(SERVER=DEDICATED)));User Id=myuid;Password=mypwd;"
'Using variation of the above with a port included.
cs = "Provider=OraOLEDB.Oracle.1;User ID=myuid;Password=mypwd;Data Source=myhostname:myport/myservicename;"

I think it is a bad idea to have more than one version of Oracle Client installed, i.e. one 32-bit and one 64-bit.
For OLE DB (i..e "OraOLEDB.Oracle") it is even not possible to have more than one version due to limitation of COM where it is based on (unless you would register the DLL every time before you run an application).
In general you can use either ODBC or OLE DB, both should work.
The most important point is: the architecture (i.e. 32-bit or 64-bit) of your Excel must be the same as the architecture of your Oracle driver! The architecture of your database does not matter.
ODBC and OLE DB drivers are provided by Microsoft ("Microsoft ODBC for Oracle" and "MSDAO") and by Oracle (e.g. "Oracle in OraClient12Home1" and "OraOLEDB.Oracle")
The Microsoft drivers are old and deprecated, you should prefer the drivers from Oracle. Microsoft drivers exist only for 32-bit, so if your Excel is 64-bit then you are even forced to use the Oracle drivers.
Another note, the version of Oracle drivers (ODBC and OLE DB) has to be the same as the version of your Oracle client, most likely you messed it up when you installed three different Oracle clients.
In case you need to install 32-bit and 64-bit client, follow this instruction: BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed

Related

OraOLEDBpus.dll: The specified module could not be found

I am facing an issue with an excel macro which connects to an Oracle database. The macro works fine on many users PC's, but on one DAAS machine, it's giving me an error when attempting to open the connection:
OraOLEDBpus.dll: The specified module could not be found
And this error as well:
An error was encountered when logging into the database
Description: Provider cannot be found. It may not be properly installed.
This is the connection string, which I don't think is an issue because it works on 20+ other users PC's.
Conn1.Open ( _
"User ID=" & strUName & _
";Password=" & PWD & _
";Data Source=" & DSN & _
";Provider=OraOLEDB.Oracle" & _
";PwdChgDlg = 0")
The OS is Win 10 64 bit and Office version is 2016 32 bit. Oracle Client 12c 32-bit has been installed on this machine.
Any thoughts on why I may be getting this error?
There are different points you have to check.
The Oracle Provider for OLE DB needs to be installed. It is not part of the bare Oracle Instant Client.
An Oracle client must be installed. The Oracle Provider for OLE DB does not work stand-alone
It must be the same architecture (i.e. 32-bit vs. 64-bit) as your MS Office
It must be the same architecture as the Oracle client
The version of the Oracle Provider for OLE DB must be exactly the same version as the Oracle client
See 32-bit Oracle Data Access Components (ODAC) and/or 64-bit Oracle Data Access Components (ODAC)
Perhaps the Oracle Provider for OLE DB exist but is not properly registered, see How do I register a DLL file on Windows 7 64-bit?
Install the 32 bit AccessDatabaseEngine.exe on this site.
Later, open cmd on this path with admin access.
Execute this command;
AccessDatabaseEngine.exe /passive

Trying to connect to an Oracle DB Server using VBA

As the title states I'm trying to connect to an oracle DB for a vba script.
I was using this article here on how to do it: https://blogs.perficient.com/2015/12/17/connectcompare-databases-excel-macro/
I just have very basic code for connecting and I'm getting an error that says "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
My code is:
Private Sub CommandButton1_Click()
Dim dbConnection As ADODB.Connection
Dim recordSet As ADODB.recordSet
Set dbConnection = New ADODB.Connection
Set recordSet = New ADODB.recordSet
conString = "Driver = {Microsoft ODBC for Oracle};DBQ=####;Uid=<####>;Pwd=<####>;"
dbConnection.Open (conString)
End Sub
One thing I am not sure on is what exactly is DBQ is. I have set DBQ to the name of the database I'm interested in. Not sure if I'm setting that parameter properly.
Thank you and all help is appreciated it.
First question: Did you install an Oracle Client on your machine?
According to your connection string you use the Microsoft ODBC for Oracle driver. Connection string must be like this:
Driver={Microsoft ODBC for Oracle};Server=myServerAddress;Uid=myUsername;Pwd=myPassword;
Note, the connection string is slightly different to the Oracle ODBC driver, see
ODBC Driver Microsoft vs. ODBC Driver Oracle
Second question: Is your Excel 32-bit or 64-bit?
The Oracle Client and the ODBC driver must be the same architecture (i.e. 32-bit vs. 64-bit) as your Excel. The ancient Microsoft ODBC for Oracle driver exist only for 32-bit. If your Excel is 64-bit then you have to use the Oracle ODBC driver.
Another note, the default Oracle Instant client does not include the ODBC driver, you have to download and install the "ODBC Package", from Oracle Instant Client Downloads
There is a comment above to use this format which I believe is correct
"DSN={MyDataSource};UID={MyUserID};PWD={MyPassword};SERVER={MyOracleServer}"
From the Microsoft documentation and here

Connecting to 32 bit Oracle client with 64 bit Excel

I'm trying to connect my Excel to Oracle with this connection string in VBA:
dim cn As New ADODB.Connection
cn.Open "Provider=OraOLEDB.Oracle;Data Source=source;User Id=userid;Password=pwd;"
I'm getting this error:
Run-time error '3706':
Provider cannot be found. It may not be properly installed.
Relevant references:
Microsoft ActiveX Data Objects 6.1 Library
OraOLEDB 1.0 Type Library
Excel is MS Office Professional Plus 2010 64-bit
Windows is 7 Enterprise, service pack 1, 64 bit
Oracle client is 11.2.0 32 bit (I think)
Oracle server is Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
Now... I have scoured the net and cannot figure out what the issue is, but my best guess is there's some 32 bit vs 64 bit conflict with drivers I'm using. I'm trying to get a sense of what path I should be taking before I involve my company's IT department to try installing stuff for me. Does the Oracle client have to be 64 bit if MS Office is? Or do I just need the 64 bit Oracle Data Access Components? I've tried a bunch of different connection strings with no success, including using MSDAORA instead of OraOLEDB.Oracle...
Yes, when you use 64-bit Excel you must install also 64-bit Oracle Client and 64-bit OLE DB Provider.
OLE DB Provider from Microsoft (i.e. MSDAORA) does not exist for 64-bit. It exists only for 32-bit and has been deprecated for very long time already.
I don't know whether you need your 32-bit Oracle Client for something else, so maybe you cannot simply remove it from your PC. Here is an instruction how to install both 32-bit and 64-bit Oracle Client on one machine.
Install Oracle Client x86 and x64
I too had the same issue and the solution is to set the oracle drivers for the excel session to 32 Bit drivers and initiate the excel.
I use the following Bat file to open the excel and it connects to oracle without any issues:
#
Set Temp=C:\Temp
Set TMP=C:\Temp
Set Oracle_Home= #YourDriveLetterhere - >M:\ORA12C\product\12.1.0\client_1
Set Path=C:\Windows;C:\Windows\System32;M:\ORA12C\product\12.1.0\client_1\bin;M:\ORA12C\product\12.1.0\client_1\nls\mesg;M:\ORA12C\product\12.1.0\client_1\network\admin;
START "" "C:\MacroFileNameWhichConnectsToOracle.xlsm"
#
The oracle server matters not.
Try opening a dos window and type c:\ tnsping yourservername
look towards installation issues.

Upload An Excel File in Classic ASP On Windows 2003 x64 Using Office 2010 Drivers

So, we are migrating an old web app from a 32-bit server to a newer 64-bit server. The app is basically a Classic ASP app. The pool is set to run in 64-bit and cannot be set to 32-bit due to other components. However, this breaks the old usage of Jet drivers and subsequent parsing of Excel files.
After some research, I downloaded the 64-bit version of the new 2010 Office System Driver Beta and installed it. Presumably, this allows one to open and read Excel and CSV files.
Here's the snippet of code that errors out. Think I followed the lean guidelines on the download page:
Set con = Server.CreateObject("ADODB.Connection")
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.14.0;Data Source=" & strPath & ";Extended Properties=""Excel 14.0;"""
con.Open
Any ideas why?
UPDATE: My apologies. I did forget the important part, the error message:
ADODB.Connection error '800a0e7a'
Provider cannot be found. It may not
be properly installed.
/vendor/importZipList2.asp, line 56
I have installed, and uninstalled/reinstalled twice.
I encountered a similar issue a little while ago and I found out that there's actually a bug in the installer package for the ACE 14 driver. The driver is being registered as "Microsoft.ACE.OLEDB.12.0". In my case I could get things to work just by changing my connection string to 12 as opposed to 14.
Evidence on the bug: Microsoft Connect
It could be the Excel version in the Extended Properties parameter. Excel 14 is for Office 2010. While the driver may be Office 2010 I would presume your Excel documents are not.
Excel 2007 - v12
Excel 2003 - v8
From http://www.connectionstrings.com for Excel 2007:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";
You could try replacing the ACE.OLEDB.12.0 with ACE.OLEDB.14.0 to match the driver version.
Here http://forums.asp.net/p/1128266/1781961.aspx is a suggestion to split your app into 32 and 64 bit components and transfer data via COM. To quote:
What you need to do is split your application into a 32 bit part and a 64 bit part, use COM interop to cross the 64/32 bit boundary. For instance, drop the code (just a simple class library compiled as 32 bit) that retrieves the Excel data into a COM+ (System.EnterpriseServices) as a "server type" application, and call that server methods from your 64 bit Windows service. This is exactly why System.EnterpriseServices are made for.
Looks like it is "14" ("14.0") for Excel. But "12" ("12.0") for ACE.
From this download:
http://www.microsoft.com/downloads/en/details.aspx?familyid=C06B8369-60DD-4B64-A44B-84B371EDE16D&displaylang=en
I found this snipplet:
**2.If you are an application developer using OLEDB, set the Provider argument of the ConnectionString property to “Microsoft.ACE.OLEDB.12.0”
◦If you are connecting to Microsoft Office Excel data, add “Excel 14.0” to the Extended Properties of the OLEDB connection string.**
HOWEVER!!!
The instructions from the download page seem to be wrong....causing some of this confusion.
From here:
http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/686d8ebb-0da3-4f0c-bf16-9c650f8dcb32
//Quote //Paul P C
The instructions are incorrect. It should be Excel 12.0. I wish they would fix this mistake at the download site.
//End Quote
I have verified that this connection string works for me:
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\MyFile.xls';Extended Properties='Excel 12.0;HDR=NO;IMEX=1;';"
I faced the same problem, finally, I realized that the error is that the connection string should be modified in 64 bit!
To get the right one, install visual basic 6 and drag the Microsoft data access control,through its wizard, open the file you want, and let it write the connection string to you.

Excel ODBC and 64 bit server

using ASP.NET I need to update an excel template.
Our server is running Windows 2008 in 64 bit mode.
I am using the following code to access the excel file:
...
string connection =
#"Provider=MSDASQL;Driver={Microsoft Excel Driver (*.xls)};DBQ=" + path + ";";
...
IF the application pool is set to Enable 32 bit applications the code works as expected; however the oracle driver I am using fails as it is only 64 bit.
If Enable 32-bit applications is set to false the excel code fails with the error:
Data source name not found and no
default driver specified
Any suggestions?
The Microsoft Office team has just released a 64-bit driver
Microsoft release a 64bit OLEDB FOR ODBC in 2008/04/04
http://www.microsoft.com/downloads/details.aspx?FamilyID=000364db-5e8b-44a8-b9be-ca44d18b059b&DisplayLang=en
Now you should able to run everything 64bit, can u try it and let us know the result and personally I think Microsoft should release a 64bit Jet Oledb 4.0, if the development team has no time to do it then just put it in codeplex.com and let other programmers do it.
There is also 2010 Office System Driver Beta: Data Connectivity Components
Link which has allowed us to open Excel 2007 (XLS) from a 64bit environment.
This download will install a set of components that can be used by non-Microsoft Office applications to read data from Microsoft Office 2010 Beta files
Our connection string
#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + filePath + ";Extended Properties=\"Excel 12.0;HDR=YES;\""
There are no office drivers for 64bit released.
The (currently) last post at this link:
MSDN Forum details a cumbersome and ugly workaround. You could also replace the Windows Service with a COM exposed assembly, if you wish. Still ugly though. :)
Install the 32-bit Oracle driver and enable 32 bit applications?

Resources