Oracle Client and networking components were not found - Excel VBA - excel

I'm trying to connect to an Oracle DB through Excel. I have installed the Instant Client from Oracle on my machine, but am getting this message when I run this code:
Sub testing()
Dim myConn As Connection: Set myConn = New Connection
Dim mySet As Recordset: Set mySet = New Recordset
Dim CONNSTRING As String
CONNSTRING = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=xxxxxx.xxx.xxxxxxxxxxx.com)(PORT=1524))" & _
"(CONNECT_DATA=(SERVICE_NAME=dev))); uid=xxxxxxx; pwd=xxxxxxxxxxx;"
myConn.Open CONNSTRING
mySet.Open "SELECT * FROM apps.ap_invoice_lines_interface", myConn, adOpenStatic, adLockBatchOptimistic, adCmdTable
Sheet1.Range("A1").CopyFromRecordset mySet
mySet.Close
myConn.Close
End Sub
The message I am getting is
The Oracle(tm) client and networking components were not found. These components are supplied by Oracle Corporation and are part of the Oracle Version 7.3 (or greater) client software installation. You will be unable to use this driver until these components have been installed

I see this error frequently when our desktop support team installs the wrong Oracle client. If your application (Excel, in this case) is 32-bit, then you also need to be using 32-bit ODBC and 32-bit Oracle client. It doesn't matter that your OS or hardware is 64-bit. What matters is the application. And it seems that most MS Office installations are 32-bit, even when installed on 64-bit Windows.

In my case, the Console project in Visual Studio had Prefer 32 bit check-marked in its Properties.
Press Alt + Enter and open the Build section.
I unchecked it and then the app worked perfectly.
By the way: I had installed Oracle client 64 bit.

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

Excel Connect to Oracle 12c Using VBA

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

With 64-bit office 2013, "Microsoft.ACE.OLEDB.12.0" cannot be loaded on 64-bit SQL server

I am using MS office 2013 64-bit (after uninstalling 32-bit office 2013) on a 64-bit computer (with windows 10), and SQL Server 2014 Express connected through IP address.
My goal is to let SQL Server read excel data, using "SELECT * FROM OPENROWSET()" statement.
My problems is: I installed "AccessDatabaseEngine_x64.exe", but when executing "openrowset()", SQL Server gives me error msg "The 32-bit OLE DB provider "Microsoft.ACE.OLEDB.12.0" cannot be loaded in-process on a 64-bit SQL Server." Please read the following so you'll know I did tons of research and trials.
The question is: should I use AccessDatabaseEngine or AccessDatabaseEngine_x64 in this case? And how?
Background - to make this question complicated:
When I had 32-bit office on my computer, and was using "import" function under "database" on SQL Server to import excel (.xlsx) data, SQL Server forced me to install AccessDatabaseEngine (the 32-bit). So I did. And the import became successful.
But I'd like to make SQL Server to read local excel files dynamically without importing, so I decided to set up excel as server using "New Linked Server" function in SQL Server, but failed. The error msg is basically "Cannot initialized the data source object of OLE DB Provider 'SQLNCLI11' for linked server "Mycomputer". Then I found "openrowset / opendatasource" statement, tried it on SQL Server, and got error msg: "The 32-bit OLE DB provider "Microsoft.ACE.OLEDB.12.0" cannot be loaded in-process on a 64-bit SQL Server." The solutions I tried were the following:
1) uninstalled AccessDatabaseEngine;
2) instialled AccessDatabaseEngine_x64 (checked registry key to make sure its registered);
3) ran configurations as per "https://blogs.msdn.microsoft.com/farukcelik/2010/06/04/accessing-excel-files-on-a-x64-machine/";
4) ran "openrowset / opendatasource" again but still got msg "Microsoft.ACE.OLEDB.12.0" cannot be loaded in-process on a 64-bit SQL Server." Only now, I couldn't import excel (.xlsx) into SQL Server any longer, I guess because AccessDatabaseEngine was uninstalled;
5) uninstalled 32-bit office;
6) installed 64-bit office;
7 ) ran "openrowset / opendatasource" again, still got msg "Microsoft.ACE.OLEDB.12.0" cannot be loaded in-process on a 64-bit SQL Server."
8) uninstalled AccessDatabaseEngine_x64;
9) installed AccessDatabaseEngine, ran "openrowset / opendatasource" again, still got msg "Microsoft.ACE.OLEDB.12.0" cannot be loaded in-process on a 64-bit SQL Server."
The "Openrowset" statement I tries was like:
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml;
Database=C:\documents\2016.xlsx',
[sheet1$]);
So it seems neither AccessDatabaseEngine nor AccessDatabaseEngine_x64 works for me for either 32-bit office or 64-bit office.
Did I miss something?
Thank you!

IIS 7 and Ms Access 2007 32 bit on Windows7 (64 bit)

System Info:
Windows Professional. 64bit.
IIS 7.0
Ms Office 2007 32 bit (from task manager)
No Visual Studio.
Running classic ASP
Need to connect with MS Access 2007 database.
<%
Dim objCon
Dim objRec
Dim objSql
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Server.MapPath("db/dbTest.accdb")
Set objRec = Server.CreateObject("ADODB.Recordset")
objSql = "select * from tblLogin;"
objRec.Open objSql, objCon
Do While not objRec.EOF
Response.Write ("<br>")
Response.Write (objRec("uid"))
Loop
%>
Using above code in .asp file.
Error message: An error occurred on the server when processing the URL.
Please contact the system administrator.
If you are the system administrator please click here to find out more about this error.
What I did:
Following above link information.
Enable 32 bit apps in IIS manager.
Enable 32 bit applications on 64 iis
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1
Using below option to select .accdb manually (is it correct way?)
%windir%\syswow64\odbcad32.exe
If it's Access 2003 or earlier the database will have the extension .mdb, not .accdb
Use the JET OLEDB driver
PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.Mappath("db/dbTest.mdb")
JET is 32 bit so you do need to enable 32 bit applications
For Access 2007 onwards use the ACE driver as per your example. ACE is 64 bit so you don't need to enable 32 bit applications, in fact you probably need to have them disabled - IIS seems to be either/or in these situations

Resources