必要なソフトウェアはすべて揃っていますか? これは、Ubuntu 12.04 に必要なものです。
sudo apt-get install php5-odbc php5-sybase tdsodbc
Linux サーバーでこれらのファイルを構成しましたか? (これらは Ubuntu 12.04 サーバーから取得したものです)
/etc/odbc.ini
# Define a connection to the MSSQL server.
# The Description can be whatever we want it to be.
# The Driver value must match what we have defined in /etc/odbcinst.ini
# The Database name must be the name of the database this connection will connect to.
# The ServerName is the name we defined in /etc/freetds/freetds.conf
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf
[mssql]
Description = MSSQL Server
Driver = freetds
Database = MyDatabase
ServerName = mssql
TDS_Version = 8.0
/etc/odbcinst.ini
# Define where to find the driver for the Free TDS connections.
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount = 1
/etc/freetds/freetds.conf
# The basics for defining a DSN (Data Source Name)
# [data_source_name]
# host = <hostname or IP address>
# port = <port number to connect to - probably 1433>
# tds version = <TDS version to use - probably 8.0>
# Define a connection to the MSSQL server.
[mssql]
host = mssql_server_ip_or_domain_name
port = 1433
tds version = 8.0
問題を引き起こしている tds バージョンのいくつかのアカウントを読みました。8.0 語がベストのように思えますが、7.5 と 7.0 で動作するようになったと言っている人も見てきました。
次に、接続をテストします。
isql mssql username password
環境によっては、ユーザー名を domain\username の形式にする必要がある場合があります。
コマンドを発行すると、次のように表示されます。
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
そして、接続コマンドは次のようになると思います(注:私はPythonを知りません):
cnxn = pyodbc.connect('DRIVER=freetds;SERVER=FOOBAR;PORT=1433;DATABASE=T2;UID=FOO;PWD=bar;TDS_Version=8.0;')