Connection of Python to Oracle through Visual Studio 2017 Error - python

I have installed the Visual Studio 2017 Community. I installed (or so I think) the Oracle 32 and 64 bit client and I managed to connect with the Visual Studio to an Oracle database from Tools -> Database Connection -> Oracle.
Now, I have a code in Python that uses the cx_Oracle library to connect to an Oracle database. When I execute it, the connection breaks and I check some blogs, it tells me that it is due to incompatibility of the Oracle client. I installed the Oracle ODAC2018 for Visual Studio.
Now, I do ALT + I to open the interactive console with the following lines (which are the same as I use to connect from the code)
import cx_Oracle
db_pass_str = "xxx"
db_usr_str = "yyy"
db_str = "database"
db = cx_Oracle.connect (db_usr_str + "/" + db_pass_str + "#" + db_str)
And I manage to make the connection to it. I am using Python 3.7 of 64 bit, my Windows machine is of 64 bit and the database is in a unix server to which I connect without any novelty by any means (sqlplus, sqldeveloper).
A similar code is the one that handles the Python code of the program that I am executing. I no longer see the way to connect. From the Pycharm achievement that the program is executed but by Visual Studio no.
Could someone help me with that?

Related

cx_Oracle.DatabaseError: DPI-1047

I am trying to run a code to create tables in oracle database.I am using Python 3.6.5 and Oracle Database 10g Express Edition Release 10.2.0.1.0 in windows 64 bit.
con=cx_Oracle.connect(config.connection)
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "C:\oraclexe\app\oracle\product\10.2.0\server\bin\oci.dll is not the correct architecture".
Seems like you are unable to connect to the Oracle DB. As pointed out here:
You need to install cx_Oracle extension for python and make sure environment variables are correctly set
In addition, see that the credentials in config.connection are correct.
Update: the latest major release of the cx_Oracle driver doesn't need Oracle libraries by default, so configuration is easier. The driver got renamed to python-oracledb, see the release announcement.
cx_Oracle 6+ needs to be using Oracle 11.2+ libraries. It seems you are linking it with your 10g DB libraries. You can install 11.2 libraries using the free Oracle Instant Client, set PATH to include them, and then connect to your 10g database - but don't stuff up PATH for other applications that need the 10g libraries. You'll probably need to use something like a BAT script to set PATH and then call python.
The Oracle 11.2 libraries must be the same 32-bit or 64-bit as Python is.
If there's anything unclear in https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html then log an issue on the cx_Oracle project at https://github.com/oracle/python-cx_Oracle/issues

Python Oracle - How to use 2 oracle clients

I need to run a django 2.1 project in a server that have an Oracle Client version 10.
But when I try to runserver I get this error:
Oracle client Library must be in version 11.2 or higher
I did some research and the obvious solution was to update the Oracle. But I can't do that because the server runs some applications that only works with Oracle Client 10.
One thing that I tought is to run two Oracle Library Clients. I did some research, one of the answers that I found:
how to set oracle client library path in python when multiple oracle client version installed
But, it's on Linux and I'm on a Windows Server 2012 R2.
How could I run 2 of these Oracle Clients?
Please, could you help me?
Oracle client ver 11.2.0.4 should be able to connect to both 10g and 12c database.
Also check this answer about SQLNET.ALLOWED_LOGON_VERSION parameter.

Connecting Python 3.x to Oracle DB

I am unable to connect to our enterprise Oracle Db using python 3/cx_Oracle.
Installed are:
python 3 -32 bit
cx_Oracle
Oracle Client 12.1.0.2.0
My connection string attempt is:
import cx_Oracle
conn = cx_Oracle.connect(user='user', password='pwd', dsn='working_dsn')
My PATH variable includes the direct path to my working Oracle library (works using SQL Dev
Error message is:
cx_Oracle.DatabaseError: DPI-1050: Oracle Client library is at version 0.0 but must be at version 11.2 or higher
I have researched the Orcale installation instructions and have found no way to connect. I have previously tried with no success, had my computer reimaged and Oracle reinstalled to ensure only one version of Oracle and still no success. I need to move from R to Python and this is the last piece I need to make the switch. I am able to connect with R using JDBC driverclass/dbConnect.
If cx_Oracle wont work, is there another option for connecting to Oracle from Python3?
Any thoughts suggestions or places to look? Other connection types used?
Thanks in advance.
pip3 install cx_Oracle
first method:
db = cx_Oracle.connect('root/root#localhost: 1523/orcl')
Second method:
db = cx_Oracle.connect('root/root#localhost: 1523/orcl')
Third method
makedsn(IP/HOST, PORT, TNSNAME)
dsn = cx_Oracle.makedsn('localhost','1523','orcl')
db = cx_Oracle.connect('root','root',dsn)
The error you are getting suggests that you have an older version of the Oracle client installed on your machine. Search the directories of your PATH environment variable for OCI.DLL. If you find an older version you'll need to remove or rename it -- just be aware that whatever application put the file there will stop working!
Another possibility is to go to a command prompt and do the following
PATH=my_path_to_instant_client;%PATH%
python test_connect.py
Finally, make sure that if your Python is 32-bit, so is your instant client installation, and if your Python is 64-bit, make sure that your instant client installation is also 64-bit.

When using cx_Oracle does Oracle need to be installed on all computers with the python application?

I created an exe of my program that communicates with an oracle database using cx_Oracle to create excel sheets. If someone else uses this exe will they need Oracle installed?
Any computer that runs Python programs using cx_Oracle will need an 'Oracle client' installed. This is the set of Oracle libraries needed by cx_Oracle that allow connections to a database. The database can be on a remote computer. The Oracle client libraries are available in three different installs:
With the Oracle Database install
With a 'full' Oracle Client install
From Oracle Instant Client
The most common in your case would be to use Oracle Instant Client, which is relatively small and is simple to install.
You download the Instant Client 'Basic' package matching your operating system and the Python architecture (32 or 64 bit). Unzip it. Set your operating system search path such as PATH (on Windows) or LD_LIBRARY_PATH or ldconfig (on Linux) to the directory you unzipped.
Instant Client Downloads and instructions are at https://www.oracle.com/database/technologies/instant-client.html
cx_Oracle installation instructions are at https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html

DPI-1047: 64-bit Oracle Client library cannot be loaded

I am trying to run oracle database in python.
Specifications:
1. Windows 7 64 bit
2. Python 32 bit 3.6 (Running on Jupyter(Anaconda Navigator)
3.Visual studio 2010 training kit module
4.Oracle instant client basic 12.2 32 bit
5.Oracle instant client basic SQL*Plus 12.2 32 bit
I have installed cx_Oracle via command
import sys
!conda install --yes --prefix {sys.prefix} cx_Oracle
import cx_Oracle
After that I have installed Oracle instant client basic 12.2 32 bit and Oracle instant client basic SQLPlus 12.2 32 bit in the same working directory from where Jupyter is connected.
I have copied both installed Oracle instant client basic and instant client basic SQLPlus in same folder and have given environment path of the same folder.
But whenever I am running the command it's giving error:
DPI-1047: 64-bit Oracle Client library cannot be loaded: "C:\oracle\product\10.2.0\client_1\bin\oci.dll is not the correct architecture". See https://oracle.github.io/odpi/doc/installation.html#windows for help
Although there is nothing of 64 bit except windows which I have search doesn't matter.
You need to install 64-bit Instant Client not 32-bit - the error is clear about this. When you run Python make sure Instant Client is in your PATH environment variable before the Oracle 10.2 directory, or any other Oracle libraries.

Categories