How To access Cx_Oracle on Pivotal cloud factory (PCF) - python-3.x

I am trying to deploy my Python code where it involves usage of Oracle connection using cx_oracle module.
I referred the below link to set up my LD_LIBRARY_PATH
Deploy instant oracle on Pivotal CloudFoundry for cx_Oracle
export LD_LIBRARY_PATH=C:/Users/pm/Documents/project_1/oracle/instantclient_19_9:${LD_LIBRARY_PATH:-}
export OCI_LIB_DIR=C:/Users/pm/Documents/project_1/oracle/instantclient_19_9
export OCI_INC_DIR=C:/Users/pm/Documents/project_1/oracle/instantclient_19_9/sdk/include
Still facing same issue once code is pushed on to PCF.
[ERR] cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory".
I have downloaded the oracle client zip file for windows 64bits 19.9 version.
And unzipped into the folder in my desktop path where my application is stored and used to push the code to pcf(C:/Users/pm/Documents/project_1/).
Could someone please guide me if any of the steps need modification and help me fix the issue.

On Windows the environment variable you want to manipulate is PATH. If that doesn't help, you can also use the environment variable DPI_DEBUG_LEVEL and set that to the value 64. That will show you all of the paths that are being tried.
You can see all of this in the installation manual.

Related

Can't connect Excel to Oracle although I already installed the drivers. (Using Excel's PowerQuery)

I have been trying for a while now, to connect Excel to Oracle through PowerPivot, but unfortunately to no success.
I am currently getting this error: An error happened while reading data from the provider. '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 have so far done the following:
1. Installed Oracle Client x64
I installed Oracle Client x64 from https://www.oracle.com/database/technologies/112010-win64soft.html. I used file win64_11gR2_client.zip. In the installation proccess I went for the option InstantClient
2. Installed Oracle's ODBC Instant Client x64
I went to https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html and downloaded both instantclient-basic-windows.x64-19.6.0.0.0dbru.zip and instantclient-odbc-windows.x64-19.6.0.0.0dbru.zip. I 'installed' them by unziping them in the same folder, and running odbc_install.
Then, I added the directory to my path environment variables and then created a new one called TNS_ADMIN and added the same directory.
3. Installed Oracle's ODBC Instant Client x32
Finally I did the same for the x32 files, but I did not add that directory to my environment variables.
I validated the correct installation by finding the drivers here:
x64 Drivers:
x32 Drivers:
Help in Troubleshooting
It is frustrating that besides the error message I can't find any way to troubleshoot this issue. Any ideas on what could it be? Any ideas on how to troubleshoot?
Thanks!
With 32 bit Oracle Instant client
Option 1 with ODBC drivers
Option 2 without ODBC drivers and ODAC client
Option 1: After installing 32 bit odbc drivers try to add only 32 bit instant client to path or if you add both clients to system path make sure 32 bit client is above 64 bit client
If the order is set correctly in system path you can verify from command prompt with where command
C:\WINDOWS\system32>where sqlplus
D:\instantclient_19_6_x86\sqlplus.exe
D:\instantclient_19_6_x64\sqlplus.exe
or with command path
C:\WINDOWS\system32>path
PATH=D:\instantclient_19_6_x86;D:\instantclient_19_6_x64;xxxxx
If set correctly You can connect via odbc File--->From Other Sources --> From ODBC
Option 2: Enables you to connect to database via ODAC Client without ODBC driversFile--->From Database --> From Oracle Database
Download ODAC 32 bit from Oracle ODP.NET_Managed_ODAC122cR1.zip.
Unzip the folder and from elevated command prompt install
D:\ODP.NET_Managed_ODAC122cR1>install_odpm.bat D:\instantclient_19_6_x86 x86 true
Here I set target directory to 32 bit instant client i.e D:\instantclient_19_6_x86
Edit: Add tns name entry in tnsnames.ora and tns_admin system variable
i,e TNS_ADMIN= D:\instantclient_19_6_x86\network\admin

Unable to connect using cx_Oracle in a Jupyter notebook on VSCode

I keep getting the following error when I try to execute the cell in a Jupyter notebook on VSCode
con = cx_Oracle.connect("/#DB")
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help
But the same works fine when I run it in Jupyter Lab.
Sometimes stuff just doesn't work in some IDEs, i am not sure what your question is, i suggest using anaconda (and maybe spyder specifically) it has worked for me with everything so far, but i don't know about cx_Oracle.
If you are using Oracle Instant Client, and it is the only Oracle software on the computer, then use the ldconfig command to set the library search path. This is always less error prone than trying to set LD_LIBRARY_PATH. See the Instant Client installation instructions.

I Have created Exe Using Pyinstaller.How to bundle Cx_racle into this

My Script is having import cx_oracle where it is connecting to Oracle DB and doing some action. I have created exe for Windows machine using pyinstaller and tried to achieve same in my machine it is working properly. When I tried in another machine without installing python it is throwing an error like below.
Please help how can I overcome this issue.
Error:
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "The specified module could not be found". See https://oracle.github.io/odpi/doc/installation.html#windows for help
[1856] Failed to execute the script
Hi Finally after long time trial and error. Found the resolution.
the machine where you want to run the stand-alone application that is using cx_Oracle please follow below steps for windows:
1.Download the instant client form the below URL.
https://oracle.github.io/odpi/doc/installation.html.
2. Unzip it and copy the path set it in Environment Variable.
3. After this, I have executed exe its worked fine foe me.

AWS Lambda cannot connect to Oracle Instant Client

I have a basic requirement of connecting an on premise Oracle database to Redshift.
I need to use AWS Lambda to connect to both the databases using python. While I achieved connection to Redshift by exporting Linux libraries of psycopg2, I am facing issues with the Oracle database.
Below are the steps followed to try to connect to Oracle on premise DB :
Installed cx_Oracle which came up with cx_Oracle.cpython-36m-x86_64-linux-gnu.so and psycopg2-2.7.4.dist-info
Installed basic oracle client lite 64 bit for linux
Set LD_LIBRARY_PATH to point to the lib files of the instant client package
When we zip our python file with the dependencies of cx_Oracle and Instant client, AWS Lambda fails with below error :
"DPI-1047: 64-bit Oracle Client library cannot be loaded: \"libclntsh.so: cannot open shared object file: No such file or directory\"
From within your lib folder, do:
ln -s libclntsh.so.12.1 libclntsh.so
(or similar, depending what versions you're using).

java.lang.NoClassDefFoundError: oracle/security/pki/OraclePKIProvider with sqlplus instantclient

I am trying to upgrade CNM (comptel) application.While installing one .jar project (Please excuse I am not from java\linux camp) i got this error:
java.lang.NoClassDefFoundError: oracle/security/pki/OraclePKIProvider with sqlplus instantclient in the installation logs.
Following is additional background:
I am using sqlplus instantclient with basic.OS is linux 64 bit Redhat 6.5
already installed java 7
created manually /usr/lib/oracle/12.1/network/admin folder. Created manually both tnsnames.ora and sqlnet.ora files in it.Provided the user who is installing the application sufficient rights over these files.
sqlplus user/pwd#servicename; is working without any problem.
I have already gone through to the question and somehow found some clue for the problem:Driver update to ojdbc7.jar gives error for oracle/security/pki/OraclePKIProvider
I could see that there are no jlib folder in my oracle_home and I have downloaded following files :osdt_core.jar,osdt_cert.jar and oraclepki.jar as suggested on one oracle standard documentation.
I am planning to create and put these files in jlib folder but my concern is would that help or just like ankur singhalLink mentioned on above post,some classpath should also be set up.
I am using /usr/lib/oracle/11.2/client64/lib/ojdbc6.jar oracle driver.
Paul

Resources