I'm trying to use Python on a RedHat machine to connect to a SQL Server database using the Microsoft provided driver. I know the driver is working because I can connect using the sqlcmd. The following in Python yields an error. It seems that pyodbc can't find the driver. Anybody know how to fix this?
conStr = 'Driver={SQL Server Native Client 11.0};Server='+server+';Database='+db+';
UID='+u+';PWD='+pw+';'
cnxn = pyodbc.connect(conStr)
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
I found that on Linux I needed to remove the braces around the driver name.
Some more info on the Driver keyword can be gleaned from here:
http://msdn.microsoft.com/en-us/library/hh568455
Actually, You can use pymssql to connect SQLServer in python.
It's easy to use, similar with MySQL-python lib.
http://code.google.com/p/pymssql/
Since pyodbc is going through unixODBC, can you confirm odbc.ini and odbcinst.ini are correctly set up?
Related
We're trying to use pyodbc to connect to an ODBC connection that's correctly configured through Win10's OBDBC Data Source Administrator (32-bit), but the driver is "SPAN Open ODBC", a string we ironically can't find anywhere on the internet.
pyodbc throws "pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (Sified (0) (SQLDriverConnect)')", and when we check [print(x) for x in pyodbc.drivers()], "SPAN Open ODBC" is indeed absent.
We've found the DLL the Win ODBC Administrator uses at C:\Windows\SysWOW64\dhodbc.dll, but don't know how / if we should pass this to pyodbc. The company Win10 ODBC Administrator lists for it is "Dharma Systems", and the only docs we can find are from 1999...
I know this isn't much to work with but we're grasping at straws here. Do we have any options?
i'm trying to connect to access database on my ubuntu 18 but i cant
self.con = pyodbc.connect(
r'Driver={Microsoft Access Driver (*.accdb)};'
r'DBQ=C:\Users\Derar\PycharmProjects\ULMS\ulms.accdb;PWD=v7WC$=3ZJ5pX?h?TM54S')
self.cmd = self.con.cursor()
I Get This Error
''`r'DBQ=C:\Users\Derar\PycharmProjects\ULMS\ulms.accdb;PWD=v7WC$=3ZJ5pX?h?TM54S')
pyodbc.InterfaceError: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')`
It looks like your trying to run code written for Windows on Ubuntu.
It looks like the path name is not a POSIX style path.
You will need to configure linux odbc properly - or just install python on Windows and run your code there...
As far as I know there is no free linux ODBC driver for accdb files. You would likely have to convert the database, use commercial software, or access the DB from Windows.
See my answer here:
Connect to MS Access in Python
I believe it's applicable to your scenario.
I have 2 machines setup:
RDP terminal with timesten client 11.2.1 and pyodbc==3.0.7 and works great. I use this connection string:
cnxn = pyodbc.connect('DSN=myhostip;UID=myusername;PWD=mypass')
local machine with timesten client 11.2.2 and pyodbc==4.0.22 (I've also tried older versions, like 3.0.7)
and when I use the connection string:
cnxn = pyodbc.connect('DSN=myhostip1;UID=myusername1;PWD=mypass1')
I get this error:
pyodbc.Error: ('HY010', u'[HY010] [Microsoft][ODBC Driver Manager] The driver is incapable of supporting the current environment attributes. (0) (SQLDriverConnect)').
Both databases on both machines are practically the same, so difference is only in timesten driver version.
Or what else could be the problem?
I have set up DSNs on both machines, and I connect to them in SQLDeveloper.
I've tried different timesten clients and pyodbc versions, but got same error everytime.
It's the only way that I know of to connect to timesten DB, can anyone please help me solve this error, or maybe tell about another way,except pyodbc, to connect?
See this answer on how to connect to TimesTen via Python:
python access to TimesTen
Use cx_Oracle via tnsnames.ora as this is the method that Oracle will support in TimesTen 18.1.3
Please avoid using any ODBC based method to connect to Python as none of these techniques are developed or tested by Oracle.
I'm setting up a python script to connect to an instance of the azure cloud database, and seeing a difference in the connection when I use IDLE vs when I try to execute the connection from a script. For example, when I do the following in IDLE:
>>> import pyodbc
>>> conn = pyodbc.connect('DRIVER={SQL Server};SERVER=<my.database.host.info>,1433', user='<my_username#mydatabase', password='password', database='database')
I'm able connect successfully and execute a basic query against one of the tables in the database.
However when I use the same connection string (copied from the IDLE console) in a script, I get the following error:
pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Usually, the issue is raised because the 32/64 bit version of python environment and odbc driver are mismatched.
You may check the python version and odbc driver version you used to run the script. You have to manage to change both of them need to be 32-bit (or both 64-bit) in order for this to work.
You can get the specified version of pyodbc extension from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyodbc.
I am trying to connect to IBM DB2 through python using pyodbc and pandas.io.sql, now the twist is I am not Super User or better to say I dont have any right to install DB2 Driver or anything else.
Is it possible to use pyodbc and pandas.io.sql to connect to DB2 with such conditions.
The code which I used so far is
cnxn = pyodbc.connect('Driver={FreeTDS}; Hostname=eee;Port=25369;Protocol=TCPIP;Database=rt;CurrentSchema=abc;UID=abc;PWD=efg;')
Error
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
Or is it possible to check if there is preinstalled DB2 driver.
At a minimum you need the IBM Data Server Driver for ODBC and CLI. You don't need to be root to install it, it's just a bunch of libraries. Find the correct version here: http://www-01.ibm.com/support/docview.wss?uid=swg24033997