5

Anyone has successfully connect to mssql thru pyodbc within sqlalchemy? I am using turbogears2 right now, and try to connect to mssql, working on a mac os platform.

Getting following error:

sqlalchemy.exc.DBAPIError: (Error) ('00000', '[00000] [iODBC][Driver Manager]dlopen({SQL Server}, 6): image not found (0) (SQLDriverConnectW)') None None
Leon Guan
  • 135
  • 2
  • 7
  • where's the code you're trying to run? – nosklo Jan 12 '11 at 03:36
  • also, did you install any odbc drivers for mssql? – nosklo Jan 12 '11 at 03:37
  • Thanks a lot for your reply. Here are some sample codes I used in python shell directly: >>> import sqlalchemy >>> engine=sqlalchemy.create_engine('mssql+pyodbc://sa:password@host/hf_export') >>> con=engine.connect() – Leon Guan Jan 12 '11 at 06:06
  • I think you are right, maybe I am missing the ODBC driver, I have pyodbc installed, apparently, it's not a driver. – Leon Guan Jan 12 '11 at 06:07
  • Did you find a driver for OSX? – Issac Kelly Jun 16 '11 at 17:03
  • Yes, I did, I used freedts, following are some notes I made when I worked on it, it's painful and I have gave up python on that project due to some reasons, anyway, hope the information can help: – Leon Guan Jun 20 '11 at 03:41

2 Answers2

4

There is a better approach than the old macports or fink, brew:

brew install freetds unixodbc

And it doesn't even need root to install it.

sorin
  • 161,544
  • 178
  • 535
  • 806
2

Easy way by MacPort

Simply do the installation by:

    sudo port install freetds +mssql +odbc +universal

This will install both freetds and unixODBC, we can either using unixODBC for ODBC management, or using iODBC shipped with Mac OS.

Compile and installation

    ./configure --prefix=/usr/local/lib/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld --enable-shared --enable-static
    make
    make install

TDSVER setting

For connecting to SQL Server 2005/8, make sure setting the tds version to 8.0, use following terminal command:

    export TDSVER = 8.0

Lauguange setting

Make sure right language has been setted:

    export LC_ALL=en_US.UTF-8
Leon Guan
  • 135
  • 2
  • 7