I am using jaydebeapi in python 3 to run queries.
I need to connect to Netezza and MySql both. my code runs both queries separately without any problem but when I run one after another it gives an error for the second one.
I close both connection and cursor for the first query (Netezza) but still get the following error:
jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.mysql.jdbc.Driver not found
The issue isn't that you need to close one connection in order to use the other. The issue is that, when jaydebeapi is using jpype for communication, you only get one opportunity to provide all of the necessary JAR file paths you may use. This can be seen in the _jdbc_connect_jpype function, here.
The fix is to pass all JAR file paths you may use during execution of your program.
I'm assuming you aren't running on Jython and instead jaydebeapi
automatically installed jpype to facilitate Python to Java
communication. This is the most likely scenario for an "out of the
box" situation. If you are using Jython, let me know.
Yu need add Class Mysql Driver and JAR file path, example to DB2 with IMB jar:
conn = jaydebeapi.connect("com.ibm.as400.access.AS400JDBCDriver",
"url",
["user", "password"],
"C:\lib\jt400.jar",)
Related
i am trying to connect my oracle 11g database to django but it didn't connect it show some error like
return Database.connect(
django.db.utils.DatabaseError: DPI-1047: Cannot locate a 32-bit Oracle Client library: "C:\oraclexe\app\oracle\product\11.2.0\server\bin\oci.dll is not the correct architecture". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
i sucessfully install 32 bit oracle client library but it still shows same error.
i am new to django and this error pops up when i use command python manage.py makemigrations it didn't create migration instead it shows this error.
it would be pleasure if someone helps me.
thankyou :)
The error is because you have a 64-bit Oracle Database installed, and its libraries are first in PATH so Python cx_Oracle tries to load them. Unfortunately your Python is 32-bit so there is a clash, which is shown by the error.
You choices are to set PATH to have your 32-bit Oracle client libraries first when you run Python. You probably don't want to do this globally since that might affect other Oracle DB tools, so you would need to do it in a cmd terminal, or set up a script that sets PATH and then calls python. You would call your new script anytime you wanted to run Python.
Overall, it's probably easier to uninstall Python, and install a 64-bit Python.
I use the neo4j python driver to write to my database.
I have my neo4j DB setup and was using ita few days ago without any issues.
Today i run my code and i get the following error:
Failed to write data to connection Address(host='localhost',
port=7687) (Address(host='xxx.x.x.x', port=7687));
("0; 'Underlying socket connection gone (_ssl.c:xxxx)'")
When i check via the browser and execute MATCH (n) RETURN n, it appears that all my querys still get executed bc i can find nodes in the database.
I shut my pc down, reinstalled neo4j and basically everything else.
(Its not only for CREATE statements but also for match statemenets)
Adding this at the end of the script worked for me.
db.driver.close()
Asusming you're using this driver, I suspect it might be related to this bug in neo4j-python-driver. It looks like their latest version fixes the bug, according to comments in the thread, but if not, maybe just downgrade back to whatever you were running before, and you should be fine.
It's usually a good idea to lock down your dependencies to avoid problems like this. Have a look at tools like pipenv or poetry if you're not familiar with them, they should save you a few headaches.
I'm uncertain where the issue lies, but the solve it to downgrade to python driver versions:
neo4j: 1.72
neobolt: 1.75
neotime: 1.75
I want to learn how to work with an Oracle Database using Python. If I understand correctly, you can use Oracle Instant Client to connect to an Oracle Database remotely, but I cannot connect. I suspect the issue is that I don't know what arguments to use for the localhost/instance combo. I believe localhost is simply my machine name, or it may be literally 'localhost' which I have tried, but I don't know how and can't find help to tell me how to locate the service name for the database instance.
In a prompt I opened python, imported cx_Oracle and used 'Easy Connect String' as specified in this sample code, using either "(my machine name)/orclpdb" or literally "localhost/orclpdb" for DEFAULT_CONNECT_STRING.
The sample code creates a variable MAIN_CONNECT_STRING which I used in a command prompt to attempt to connect to the remote database:
cnxn = cx_Oracle.connect(MAIN_CONNECT_STRING)
cx_Oracle.DatabaseError: ORA-12541: TNS:no listener
I find answers that seem to be based on this, or others referring to tnsnames.ora, or listener.ora which are files I don't have. I also tried using instantclient-sqlplus-nt-12.2.0.1.0.
Background:
Windows 7
I downloaded cx_Oracle-6.1-cp27-cp27m-win32.whl and
instantclient-basic-nt-12.2.0.1.0.zip
I put the .whl into "C:\Python27\Scripts\"
I used python -m pip
install cx_Oracle --upgrade to install cx_Oracle.
I unzipped the instant client zip and put the child folder here
"C:\instantclient_12_2"
I added ;C:\instantclient_12_2 to the end of PATH.
Maybe you can use the installation instructions found in the
cx_Oracle documentation for Windows, cx_Oracle for Windows
Uninstall first the cx_Oracle you are using then try to follow the instructions found in the link above.
I am attempting to connect to SQL Server running on Windows XP system from a *nix system on a local server via pymssql. However, the connection fails as shown below
db = pymssql.connect(host='192.168.1.102',user='www',password='test',database='TestDB')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pymssql.pyx", line 457, in pymssql.connect (pymssql.c:6041)
raise InterfaceError(e[0])
pymssql.InterfaceError: Connection to the database failed for an unknown reason.
Things I've tried:
Set SQL Server and browser to run as a network server.
Setup a user 'www'. I also tested this user locally in SQL Studio.
Turned off Windows firewall (temporarily of course).
I am missing SOMETHING - I just don't know what it is. I tried all of the infinite menu options on Windows to no avail. One thing I noticed is that if the Windows Firewall is on (I setup an exception for SQL Server) python pauses a long time and then gives the error. If the firewall is off the error is instant.
Are there any logs I can look at in SQL Server?
Got it! I think the source of the problem was not giving Free TDS the attention it needs. Free TDS is apparently the driver behind pymssql and provides for connectivity to other databases - SQL Server being one of them.
The freetds.conf file is located in /usr/local/etc on my system (Mac Book Pro).
This file contains the defaults from the install. However, I had previously added a definition so that I could connect but forgot about it and unfortunately did not take notes on it.
Anyway, here is an example of what I appended to freetds.conf:
[SomeDB]
host = 192.168.1.102
port = 1219
tds version = 7.0
However, what is puzzling is that I set the port to 1219. I had it set manually to 1433 in SQL Studio. Also, I am using TDS version 0.82 so I don't know how 7.0 fits in.
Next, I tested connectivity using 'tsql' as follows:
tsql -S SomeDB -U www
I enter the password and get a command-line which allows for SQL queries.
Next, I tested connecting using pymssql as follows:
db = pymssql.connect(host='SomeDB',user='www',password='cylon',database='TestDB')
As you can see, I needed to use the host name from the freetds.conf file and NOT the IP directly. I then tested a simple query with additional python code to insure I could read from the database.
I hope this helps someone else in the future.
It looks like you've got this solved, but for anybody else from google that lands here: check to make sure mixed-mode authorization is turned on on your MS SQL Server. It defaults to only allowing Windows authorization, and that will cause this error in pymssql.
is it a windows machine u working on? specify the port 1433.
it seems to be a bug in the mssql client api, which tries to use Namedpipes instead of TCP/IP.
At work we have Oracle 7. I would like to use python to access the DB.
Has anyone done that or knows how to do it?
I have Windows XP, Python 2.6 and the cx_oracle version for python 2.6
However, when I try to import cx_oracle i get the following error:
ImportError: DLL load failed the module could not be found
Any help is appreciated!
Matt
cx_Oracle is currently only being provided with linkage to the 9i, 10g, and 11i clients. Install one of these clients and configure it to connect to the Oracle 7 database using the proper ORACLE_SID.
Make sure you have the location of the oracle .dll (o files set in your PATH environment variable. The location containing oci.dll should suffice.
I was running into that same problem at work. I finally dropped trying to use cx_Oracle and went with adodbapi. It worked with Oracle 8.
If you have ODBC configured then you can use it. It is available with ActivePython or as win32 extensions. You will obtain connection with:
connection = odbc.odbc('db_alias/user/passwd')
Optionally you can use Jython and thin JDBC client. Instalation of client is not required. With Jython you have access to db via db url:
db = DriverManager.getConnection(db_url, usr, passwd)
where db_url looks like:
jdbc:oracle:thin:user/passwd#machine_ip:port:dbname