Whenever I tried using pyodbc to connect to a Rocket UniData/UniVerse data I kept running into the error:
pyodbc.Error: ('00000', '[00000] [Rocket U2][U2ODBC][0302810]Unable to allocate sufficient memory! (0) (SQLDriverConnect); [00000] [Rocket U2][U2ODBC][0400182]Connection not open. (0)')
My code looks as follows:
import pyodbc
conStr = 'Driver={U2 64-Bit ODBC};Database=myDb;Server=localhost;UID=user;PWD=password'
conn = pyodbc.connect(conStr)
cursor = conn.cursor()
I actually found that the simplest way to fix this error was to create a System DSN and then changed my code to the following:
import pyodbc
conStr = 'DSN=myTestDsn;UID=user;PWD=password'
conn = pyodbc.connect(conStr)
Related
I am using this code to connect with oracle database:
import cx_Oracle
conn_str = u"jbdc:oracle:thin:#****_***.**.com"
conn = cx_Oracle.connect(conn_str)
c = conn.cursor()
However, I am getting this error:
ORA-12560: TNS:protocol adapter error
How can I resolve it?
Thank you
You cannot use a JDBC thin connect string to connect with cx_Oracle (or the new python-oracledb). You must use either an alias found in a tnsnames.ora file, or the full connect descriptor (such as that found in a tnsnames.ora) file or an EZ+ Connect string. An example follows:
conn_str = "user/password#host:port/service_name"
With the new python-oracledb driver you can also do this:
import oracledb
conn = oracledb.connect(user="USER", password="PASSWORD", host="my_host",
port=1521, service_name="my_service")
See the documentation for more details.
We currently use a program that creates and writes large datasets to databases, but the process can take a long time. We are trying to incorporate cursor.fast_executemany = True from sqlalchemy to improve the write times to these databases. My code errors out when I try to create an engine using SQLite3 and pyodbc here:
import pandas as pd
from sqlite3 import connect
import pyodbc
from sqlalchemy import create_engine
engine = create_engine('SQLite3 ODBC Driver+pyodbc:///C:\\Users\\Documents\\PythonScripts\\FLR.sosat')
conn = engine.connect()
c = conn.cursor()
We have tried numerous ways where we specify the driver and server and things like that like the following:
# conn = pyodbc.connect('DRIVER={SQL Server};'
# 'SERVER=localhost;'
# 'DATABASE=C:\\Users\\Documents\\PythonScripts\\FLR.sosat')
The single engine line seems to be the closest to working due to us receiving driver and server errors from the commented out code above. We have downloaded the ODBC driver from http://www.ch-werner.de/sqliteodbc/
We receive the ArgumentError: Could not parse rfc1738 URL from string.
We would appreciate any help or ideas on how to get the SQLite3 database to pyodbc and how to improve the write speed. Thanks!
Note the .sosat file is a database file that uses sqlite3, it should work like any .db file
We tried the fix from here: Connect to SQLite3 server using PyODBC, Python and that did not work for us, we received the driver error:
InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
What you are trying to accomplish will not work for two reasons:
Reason 1:
SQLAlchemy does not support pyodbc as a DBAPI layer for SQLite.
Reason 2:
Even if SQLAlchemy did support sqlite+pyodbc:// the SQLite ODBC Driver would have to support "parameter arrays", an optional ODBC feature that fast_executemany = True uses to do its magic. Not all ODBC drivers support fast_executemany = True as shown here. A quick test with vanilla pyodbc shows that "SQLite3 ODBC Driver" doesn't support it, in fact it crashes the Python interpreter:
crsr.fast_executemany = True
crsr.executemany(
f"INSERT INTO {table_name} (txt) VALUES (?)", [("foo",), ("bar",)]
)
# Process finished with exit code -1073741819 (0xC0000005)
(Error 0xC0000005 is "Access Violation".)
Have you tried
import sqlite3
db = r'C:\Users\Documents\PythonScripts\FLR.sosat'
conn = sqlite3.connect(db)
print('connection established')
I am trying to connect to Sybase using pyodbc.
conn = pyodbc.connect('DRIVER=/usr/lib64/libodbc.so;SERVER=DBName;DATABASE=Test;UID=username;PWD=password')
When i execute the above I get the following error.
Error: ('IM002', '[IM002] [unixODBC][SAP][ODBC Driver Manager] Unable to load resource file (-620) (SQLDriverConnect)')
I can connect to sybase using sqsh so the username and password are correct. Any other suggestions?
I am using Ubuntu 16.04. Not sure if that makes a difference.
try this please
import pyodbc
connection_string = "Driver=SQL Anywhere 17;Server=demo17;UID=dba;PWD=sql;DBN=demo"
connection_object = pyodbc.connect(connection_string)
cursor = connection_object.cursor()
sql_string = "select 1"
result = cursor.execute(sql_string)
counter = result.fetchone()[0]
print(counter)
connection_object.close()
I was using the incorrect driver.
It is a custom driver so I can't share.
I need to connect to the Teradata database using python. I have used the below code:
import pyodbc
import teradata
cnxn = pyodbc.connect('DRIVER={Teradata};SERVER=<*ServerName*>;DATABASE=<*Database Name*>;UID=<*User ID*>;PWD=<*Password*>',ansi=True, autocommit=True)
cur = cnxn.cursor()
But on executing, I am getting the error as :
Error: ('28000', '[28000] [Teradata][ODBC Teradata Driver] Not enough
information to log on (0) (SQLDriverConnect); [28000] [Teradata][ODBC
Teradata Driver] Not enough information to log on (0)')
What I am missing here ? What else needs to be included to set up the connection ?
Also, is there any other way to set up the connection. While looking, I have come across teradata.UdaExec(). Can this also be used?
The following works in CentOS Linux server.
create a file with the below contents in any file (say odbc.ini)
[ODBC Data Sources]
my_data_source=tdata.so
[my_data_source]
Driver=/path/to/teradata/drivers/tdata.so
DBCName=<td_hostname>
LastUser=<user_name>
Username=<user_name>
Password=<password>
Database=<default_database>
DefaultDatabase=<default_database>
TDMSTPortNumber=<teradata_port>
set ODBCINI variable to the path of the odbc file
export ODBCINI=/file/to/path/of/odbc.ini
note: you can skip the setting of ODBCINI env variable by creating the odbc.ini file in the home directory i.e. /home/user/.odbc.ini (note that the .odbc.ini is a hidden file with a dot prefix in the file name)
now to connect to Teradata use the below snippet.
import pyodbc
pyodbc.pooling = False
conn = pyodbc.connect('DSN=my_data_source',ansi=True, autocommit=True)
I'm new to Python + Flask + Flask Appbuilder but I am a professional Java developer. I've been working on a small app that I initially used SqlLite and now I want to move into SQL Server, which will be the production database.
I can't seem to get the connection right.
I have tried using a DSN but I get an error message indicating there is a mismatch between the driver and something else (Python?). The searches on this error seem to indicate the driver is 32 bit and Python is 64. Still I can't get that working so I thought I'd try to connect directly. I'd prefer not using a DSN anyway. I've searched the web and can't find an example that works for me.
I have imported pyodbc. This is the current way I'm trying to connect:
params = urllib.quote_plus("DRIVER={SQL Server};SERVER=devsql07:1433;DATABASE=DevOpsSnippets;UID=<user>;PWD=<password>")
SQLALCHEMY_DATABASE_URI = "mssql+pyodbc:///?odbc_connect=%s" % params
This produces the following error message:
2016-02-17 07:11:38,115:ERROR:flask_appbuilder.security.sqla.manager:DB Creation and initialization failed: (pyodbc.Error) ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]Invalid connection. (14) (SQLDriverConnect); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (ParseConnectParams()). (14)')
Can anyone help me get this connection correct?
I really appreciate any help.
if you are using pyodbc you should be able to connect this way
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=yourServer;DATABASE=yourDatabase;UID=;PWD=')
#putting to use
SQL = "select Field1, Field2 from someTable"
cursor = cnxn.cursor()
cursor.execute(SQL)
row = cursor.fetchall()
for r in row:
print r[0] #field1
print r[1] #field2
The port should be specified through a comma. Specify the connection string as
DRIVER={SQL Server};SERVER=devsql07,1433;DATABASE.....