I'm trying to connect to an Oracle Database from an Excel application and whithout a DNS. I found on a website that it's possible to use ADO, so this is why I tried to do. I'm new to this so I juste copied what I found on this website.
Here is my code so far :
Sub ADOtest()
Dim connection As New ADODB.connection
connection.ConnectionString = "UID = user1; PWD= my_pwd; DRIVER = {Microsoft ODBC for Oracle; Server= localhost; Database= orcl.my_domain;"
connection.Open
End sub
When I run this code, I get an error saying that the driver was not found.
The problem is that I have no idea of what I have to do with the driver (how to install it and configure it). Plus, I don't know which one I should use : I've read that there is a driver from Microsoft, another one from Oracle and also I've seen something about providers like msdaora.
The program will be used by many users, so I would like to choose the solution that is the lightest (not much to install on computers).
Thank you !
For COM based ADO (ADODB) you can use the OLE DB Providers.
One is from Oracle, called "Oracle Provider for OLE DB". You can download it from 32-bit Oracle Data Access Components (ODAC) and NuGet Downloads (assuming your Excel is 32-bit). The connection string would be
"Provider=OraOLEDB.Oracle;Data Source=orcl;User ID=myUsername;Password=myPassword"
The other one is from Microsoft. Please note, this provider is deprecated, you should not use it for new projects. Usually it should be available on your Windows. Be aware, like the provider from Oracle it also requires an Oracle Client to be installed on the PC! The connection string would be
"Provider=MSDAORA;Data Source=orcl;User ID=myUsername;Password=myPassword"
The data source is usually defined in tnsnames.ora file or at a LDAP server, for example:
orcl.my_domain =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(Host = localhost)(Port = 1521))
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
If you don't have such entry you can put everything into the connection string, e.g.
"Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=myUsername;Password=myPassword"
Perhaps you have to enclose the data source value by double-quotes ("), I am not sure.
So, in any case you would have to install an Oracle Client at all PC's.
Where is your database server hosted? In your question you say Server=localhost;, this would be quite unlikely, i.e. it is in contradiction to The program will be used by many users. I doubt everybody has an Oracle Database server installed on his local host.
Related
I am trying to get data from a Microsoft Access Database. The issue is the number of constraints I'm under:
I have to use 64 bit Python
The access database is made up of linked tables to a different database
The other database requires a 32 bit Oracle driver
Therefore, I have the Access Database stored locally and am trying to connect to that using PyODBC.
I've tried looking around and messing with the connection string but this problem seems pretty unique.
This is currently a modified version of what I have:
import pyodbc
dbPATH = r'C:\path\to\database.accdb'
UID = 'username'
PWD = 'username'
driver = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
credentials = r'DBQ=%s;UID=%s;PWD=%s'%(dbPATH, UID, PWD)
conn_str = driver + credentials
connection = pyodbc.connect(conn_str)
cursor = connection.cursor()
cursor.execute("select * from [table_name];")
for row in cursor.fetchone():
print(row)
This is the error I typically get:
pyodbc.Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] ODBC--connection to '{Oracle in OraClient11g_home1_32bit}' failed. (-2001) (SQLExecDirectW)")
Which is surprising since this is the driver and connection that the access database uses to connect to the other data source.
I have tried setting
pyodbc.pooling = False
but that did not change anything.
You have two constraints that are mutually exclusive:
I have to use 64 bit Python
... and ...
The other database requires a 32 bit Oracle driver
64-bit processes cannot use 32-bit ODBC drivers; they are simply not compatible. If the rest of your stack (Oracle ODBC driver, Microsoft Office/Access application(s)) is 32-bit then you will need to use a 32-bit version of Python if you want to work with the linked tables as you've described.
Additional Note: Your statement that "The other database requires a 32 bit Oracle driver" is dubious. Client-server databases like Oracle, SQL Server, etc., don't particularly care if they receive requests from a 32-bit client or a 64-bit client. There may be differences in the details on the client side, but that's for the ODBC Driver (and/or the ODBC Driver Manager) on the client to figure out.
I'm running a VBA script I used to use when connecting to Oracle database through Excel 32-bit but now I'm using Excel 64-bit.
VBA code:
Set cn1 = New ADODB.Connection
Set rs1 = New ADODB.Recordset
cn1.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=BR1P1;Uid=BR1USER;Pwd=myPass"
cn1.Open
rs1.Open Query, cn1
When I execute "cn1.open" I get this error:
"Run-time error'-214746... [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
Then I tried to solve adding a new data source:
ODBC Data Source Administrator (64-bit)> File DSN> click in Add...> from list I select: Oracle em OraClient11g_home1 ("Oracle em" means "Oracle for", my OS in in portuguese)> Next> browse to the file: "C:\Windows\System32\odbcad32.exe"> Next> Finish
Doing so system will give me the driver name: "Oracle em OracleClient11g_home1"
Afterwards it will prompt for Service Name, User Name and Password. I inform server Name according to my TNSNAMES.ORA
Back to VBA I changed the code according to the driver name:
cn1.ConnectionString = "Driver={Oracle em OracleClient11g_home1}"
Now when execute "cn1.Open" in VBA I receive this new error message:
"Run-time error'-214746... [Oracle][ODBC]ORA-12560: TNS:protocol adapter error"
My TNSNAMES.ORA file is like this:
BR1P1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = myhost.com)(PORT = 1575))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = BR1P1)))
Well I'm just stucked on this. Please I appreciate any help on this.
It's being a pain after I changed my MS Office to 64-bit version.
The Microsoft ODBC for Oracle exist only for 32-bit thus you cannot use it for 64-bit Excel.
If you like to use the 64-bit ODBC driver from Oracle then you must install it. Download the driver from 64-bit Oracle Data Access Components (ODAC) Downloads
The ConnectionString format of the Oracle ODBC Driver is different to the format of the Microsoft ODBC driver, see
Microsoft ODBC Driver - Connection String Format and Attributes
Oracle ODBC Driver - Format of the Connection String
or https://www.connectionstrings.com/oracle/ -> ODBC drivers
So, for Oracle your ConnectionString
Driver={Microsoft ODBC for Oracle};Server=BR1P1;Uid=BR1USER;Pwd=myPass
will be
Driver={Oracle em OracleClient11g_home1};DBQ=BR1P1;Uid=BR1USER;Pwd=myPass
Using the Oracle client:
C:\temp> tnsping usrrprd
TNS Ping Utility for 32-bit Windows: Version 12.2.0.1.0 - Production on 06-JUL-2018 10:09:51
Copyright (c) 1997, 2016, Oracle. All rights reserved.
Used parameter files:
C:\Oracle12\product\12.2.0\client_1\network\admin\sqlnet.ora
Used LDAP adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = crs-rrdw-prd.tdbank.ca)(PORT = 1535)) (CONNECT_D
ATA = (SERVER = DEDICATED) (SERVICE_NAME = USRRPRD.tdbank.ca)))
I can access the server fine using sqlplus linqpad, sqldeveloper and even Visual Studio. Excel is stumping me, however. Using Microsoft Query and the Microsoft ODBC for Oracle Connect, I get:
Using the Data Connection Wizard, it connects and displays the tables and views. However, when I try to retrieve one, I get a different error:
Honestly, I'd take either approach, though since the table I want to see is large, Microsoft Query might be preferable.
How can I resolve these errors?
Hi I'm attempting to use some of the SQL code I've written in SQL developer through a direct database connection via Excel. Unfortunately the error message I receive whenever I try is:
"Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."
I've painstakingly installed the Oracle 64bit client on my PC, so that at least, should be working. Unfortunately I've spent the best part of two days looking up solutions on the internet with no success. Does anyone know how I can force Excel to use my 64bit client or avoid this error in another way?
Update:
I believe despite my best efforts the problem is somewhere within my TNSNAMES file since I can't connect using SQL Plus either. Here's a redacted version of my Connection string. The ommitted details are correct since they are the same as I'm using for SQL Developer. Am I missing something?
DB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))
)
(CONNECT_DATA = (SID = SID1)(SERVER = DEDICATED)
)
)
DB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))
)
(CONNECT_DATA = (SID = SID2)(SERVER = DEDICATED)
)
)
Obviously, it's something small in your machine settings or configuration.
I would suggest you will look at your machine's PATH environment variable. It may refer to an older version of Oracle Server or the Oracle Client Components.
Make sure you know what you are using to access Oracle from Excel, JDBC or ODBC?
It's always the little details which drive us crazy.
Did you see any of these answers?
SQL Server 2012 connectivity to Oracle
Getting MS Office 2013 (32 bit) Excel and Access to connect to Oracle database when both 32 and 64 clients are installed
and I found this link, too complicated to copy everything to the answer:
Connect To Oracle Via ODBC Driver
And you can try connecting to Oracle with ODBC using ODAC or Oracle client, download ODAC112030_x64.zip from Oracle's website. Here's a link on how to install it SETTING UP AN ORACLE ODBC DRIVER AND DATA SOURCE
Good Morning,
I am trying to connect to a Mysql Data base using SqlYog, I have created a new connection and I have entered all the necessary informations (login,password & port). But when I click “ok”, I get this error message (Error 2007 : Protocol mismatch; server version = 1, client version = 10) . I have pinged the data base and it responds me successfully !!!
Could you please tell me how can I solve this problem, I need to access to the data base urgently.
Thanks a lot.
This is usually due to using a very old MySQL server (before 3.22.x) which has a different protocol version.
You can take a look at this link to see what all server versions are supported.
To check your server protocol version, go to the MySQL command line and type:
SHOW VARIABLES LIKE "%version%"
SQLyog supports only the protocol version 10.