I tried connecting to oracle using cx_oracle in python but getting an error.
Tried this:
I even formatted my machine and updated java version.
Amazon Python 2.7 Lambda: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so"
but still did not work.
Versions Used : python 3.7, Anaconda 3.7
import cx_Oracle
connect_string = 'Username/password#hostname:port/sid'
connection = cx_Oracle.connect(connect_string)
cursor = connection.cursor()
cursor.execute("Select * from table_name")
for rows in cursor:
print(rows)
Error : cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/odpi/doc/installation.html#macos for help
Related
I have a system with python 3.6 and I also alt installed 3.9.
I am using ibm_db and ibm-db_dbi packages and when I connect to DB using python3.6 connection works fine. But when I connect using python 3.9 it fails with:
>>> ibm_db.connect(dsn2, "","")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: [IBM][CLI Driver] SQL1032N No start database manager command was issued. SQLSTATE=57019 SQLCODE=-1032
Even with ibm_db_dbi I get the same error. I verified the ssl certs and they are being picked up correctly.
dsn2 = 'DATABASE=MYDB;UID=db2inst1;PWD=XXXXXXXX;PORT=50001;PROTOCOL=SSL;HOSTNAME=myhost;SSLClientKeyStoreDB=/usr/local/python3.9/lib/python3.9/site-packages/component/rest/data/ssl'
No errors in diag logs. Any pointers to why is the connection not working? Is it looking for something in python3.6 which is missing in 3.9?
I have made an alt install of python3.9. So both 3.6 and 3.9 co exist. and I open python interpreter of different versions to run the command. OS is Centos. If I remove SSL from dsn connection works fine on 3.9 as well.
We have an oracle database and i am trying to connect to oracle database using python in linux. We have installed "sqlalchemy" , "cx_Oracle" libraries.
When i try to execute the below python script, i am getting below error.
Error: sqlalchemy.exc.DatabaseError: (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". See
https://oracle.github.io/odpi/doc/installation.html#linux for help
(Background on this error at: http://sqlalche.me/e/4xp6)
Is there any way without installing "Instant Client" , i can connect to oracle database and execute .... ?
Please help me with any suggestion
Below is the code.
import sqlalchemy
from sqlalchemy import types,create_engine
conn = create_engine('oracle://User:password#hostname:1521/?service_name=ABCD')
cur = conn
ABC = []
select = cur.execute("select EMPLOYEE_ID,EMPLOYEE_NAME from EMPLOYEE")
for line in select:
ABC.append(line)
print(ABC)
I am new to python and oracle, I have written the code for the connection to oracle database 11g but it gives an error:
import cx_Oracle
con=cx_Oracle.connect('sys/Satyam123#localhost/xe')
con.close(
)
It gives the following error in pycharm:
C:\Users\DELL\venv\module2\Scripts\python.exe
C:/Users/DELL/Desktop/PYTHON/module2/check.py Traceback (most recent
call last): File "C:/Users/DELL/Desktop/PYTHON/module2/check.py",
line 2, in
con=cx_Oracle.connect('sys/Satyam123#localhost/xe') cx_Oracle.DatabaseError: DPI-1047: 32-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
Please download and install Oracle Client. (There are several editions of Oracle Client, but the instant one will do):
http://download.oracle.com/otn/nt/instantclient/122010/instantclient-basic-nt-12.2.0.1.0.zip
Once it is installed, the cx_Oracle python module will look for the Oracle libs (OCI) and load them.
I had the same issue. Please follow the link https://oracle.github.io/odpi/doc/installation.html and install Oracle Instant Client 64-bit or 32-bit as per your system version. Once this is installed python would automatically be able to find Oracle Client libraries and you can successfully connect to the database.
It seems like,there is issue related to PATH.You can try to install package with the IDE terminal.In your case just try to install a package with pycharm terminal.
After that try to execute below script:
import cx_Oracle
import db_config
user="test"
pw="test"
dsn="localhost:port/TEST" #here TEST is service id
con = cx_Oracle.connect(user, pw, dsn)
cur = con.cursor()
cur.execute("select * from test_table")
res = cur.fetchall()
for row in res:
print(row)
Still having an issue then you can refer :
[https://oracle.github.io/python-cx_Oracle/samples/tutorial/Python-and-Oracle-Database-Scripting-for-the-Future.html]
I have this small script which tryes to connect to a server running a oracle database (11g).
import os
import sys
import jpype
import jaydebeapi
if("JAVA_HOME" not in os.environ):
os.environ["JAVA_HOME"] = "c:\Program Files\Java\jdk1.8.0_45"
ODBC_DRIVER = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ojdbc6.jar")
print("\tPYTHON VERSION", sys.version)
print("\tJAVA_HOME", os.environ["JAVA_HOME"])
print("\tDEFAULT JVM PATH", jpype.getDefaultJVMPath())
print("\tODBC_DRIVER", ODBC_DRIVER)
try:
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path={}".format(ODBC_DRIVER))
conn = jaydebeapi.connect("oracle.jdbc.driver.OracleDriver",
["jdbc:oracle:thin//192.168.10.33:1521", "<user>", "<passw>"],
ODBC_DRIVER)
except Exception as e:
print(e)
sys.exit(-1)
sys.exit(0)
The output with the thrown exception:
PYTHON VERSION 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)]
JAVA_HOME c:\Program Files\Java\jdk1.8.0_45
DEFAULT JVM PATH c:\Program Files\Java\jdk1.8.0_45\jre\bin\server\jvm.dll
ODBC_DRIVER d:\path\to\ojdbc6.jar
close_fds is not supported on Windows platforms if you redirect stdin/stdout/stderr
As a reference I mostly used small tutorials which connect to a oracle database. Their code lookst essentially the same.
By looking for a solution I have found that python should support close_fds from version 2.6.x
I'm not sure where to start looking.
More information on jpype and jaydebaapi:
JayDeBeApi3 (1.3)
JPype1-py3 (0.5.5.2)
Both were installed through pip.
I would recommend using python >=2.7.x (which is fine in your case because you are using a higher version).
Use JPype1 0.5.7 as recommended by JayDeBeApi 0.2.0, which is the latest version.
Also, since you are starting the JVM yourself, you don't need to specify the 3rd argument (driver) in the connect statement. Or you can comment out the startjvm and keep connect statement as it is. Jpype does the same (i.e, startjvm if you specify the driver jar as 3rd argument in connect statement).
I've been connecting to a MSSQL SERVER 2008 database using Microsoft SQL Server Management Studio graphic interface, as depicted in this screenshot
I would like to connect to this database using a python script. I installed pymssql and I've failed to connect to the database. I tried the following command:
import _mssql
conn = _mssql.connect(server="POLIVEIRA-PC\\MSSQLSERVER2008", user="POliveira-PC\\POliveira", password="my_password", database="database_name")
with and without the user and password flags. I always end up with this error:
Traceback (most recent call last):
File "", line 1, in
File "_mssql.pyx", line 1887, in _mssql.connect (_mssql.c:20477)
File "_mssql.pyx", line 632, in _mssql.MSSQLConnection.init (_mssql.c:6169)
_mssql.MSSQLDriverException: Connection to the database failed for an unknown reason.
Can you help me connect to this database using Python (either using pymssql module or not). I'm not experienced with Python, nor do I with SQL, therefore I would like to do it in the simplest manner possible.
I'm running Windows 7 64 bit. Pyhton v2.7.9
I recommend you to use pyodbc, if you're using anaconda, use the 3.0.10 version of pyodbc, example:
import pyodbc
from urllib.parse import quote_plus
params = quote_plus("DRIVER={SQL Server};SERVER=POLIVEIRA-PC\\MSSQLSERVER2008;DATABASE=dbname;UID=userid;PWD=password")
try: cnxn = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)
except Exception as e:
raise SystemExit('Error: Conexion Base de Datos SQL %s' % e)
And if the problem is a remote connection in this links they talk about it
https://blogs.msdn.microsoft.com/walzenbach/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008/
http://akawn.com/blog/2012/01/configuring-sql-server-2008-r2-express-edition-for-remote-access/
Hope this works
You need to create a login with SQL Server authentication and then connect with this user:
(you'll need to connect this login to a user etc., but that's unrelated to logging in), then use
import pymssql
pymssql.connect(host=r"POLIVEIRA-PC\MSSQLSERVER2008", user='logintest', password='secret', database='database_name')
don't use the _mssql module directly.