简体   繁体   中英

Can't connect to Database via turbodbc

TLDR: Don't use the unicode drivers, use ansi!


I want to connect to a DB via TurbODBC instead of Pandas/SQLAlchemy.

What I did by now:

  • Installing unixodbc
  • installing turbodbc
  • installing iODBC
  • installing Mysql Connector for ODBC
  • Configuring Port and Server in iODBC Admin
  • Testing Connection in iODBC Admin with User and Pass: Worked fine!

Now I tried to do the following:

from turbodbc import connect
connect(dsn="mydsn", user="myuser", password="mypass")

and got the following error message:

---------------------------------------------------------------------------
DatabaseError                             Traceback (most recent call last)
<ipython-input-2-bbbc3a4c2880> in <module>()
----> 1 connect(dsn="mydsn", user="myuser", password="mypass")

/Users/myuser/anaconda2/lib/python2.7/site-packages/turbodbc/exceptions.pyc in wrapper(*args, **kwds)
     31             return f(*args, **kwds)
     32         except InternError as e:
---> 33             raise DatabaseError(str(e))
     34     return wrapper

DatabaseError: ODBC error
state: H

I don't know what to do now and didn't found any issues regarding this error.

I'd be very happy if anybody could help me, thanks in advance! ;-)

UPDATE

I tried in R with RODBC, worked fine. So I'm sure this is a problem of TurbODBC, but am not able by now to debug the (C++ i think) code....

UPDATE #2

I changed the Mysql Connector for ODBC driver in the settings file .odbc.ini to the ansi driver. I thought this has to be the unicode due to the Database, which contains unicode tables... but with ansi, everything works fine (only) when I set the encoding by manual to utf8 in the settings file while using ansi driver. Don't know why or how the error occurs, but this workaround works.

Here are a few suggestions:

  1. The error message seems somewhat incomplete. This may indicate that turbodbc is built incorrectly (it is tested with unixodbc headers).
  2. If turbodbc is built with unixodbc, it will use unixodbc's configuration of data sources. It will not use configurations configured for iODBC.
  3. You can check if unixodbc can connect to your database with isql <dsn> <user> <password> -v .
  4. Make sure the environment variables for unixodbc point to your odbc.ini . This is accomplished with export ODBCINI=/path/to/odbc.ini .
  5. Tweak your odbc.ini until isql can connect successfully. Then try turbodbc again.

If you still think it is a bug, please report it at https://github.com/blue-yonder/turbodbc/issues .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM