9

iODBCを使用してMac開発マシンからMicrosoftSQLServerに接続しようとしています。何をしてもUnable to connect to data source、FreeTDSドライバーからエラーメッセージが表示されます。さまざまなマニュアル、ブログ投稿、StackOverflowの質問を参考にした後、私は終わりを告げました。

私はMacOSX 10.7.4を使用しており、FreeTDSバージョン0.91がHomebrewからインストールされています。これが私がしていることです:

$ brew install freetds
$ mkvirtualenv odbc
$ workon odbc
$ pip install pyodbc

$ tsql -H localhost -U mydbusername -P mydbpassword -p 1433 
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> quit

上記は接続して機能しますが、次のようになります。

$ iodbctest
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.0607.1008

Enter ODBC connect string (? shows list): driver={TDS};server=localhost;uid=mydbusername;pwd=mydbpassword;database=mydbname
1: SQLDriverConnect = [FreeTDS][SQL Server]Unable to connect to data source (0) SQLSTATE=08001
1: ODBC_Connect = [FreeTDS][SQL Server]Unable to connect to data source (0) SQLSTATE=08001

最終的にはPyODBCを介して使用することを計画しているので、それも試しました。

$ python
Python 2.7.3 (default, Jun 22 2012, 00:35:38) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc
>>> c = pyodbc.connect(driver='/usr/local/lib/libtdsodbc.so', host='localhost', name='mydbname', uid='mydbusername', pwd='mydbpassword')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('08001', '[08001] [FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')

I've tried all manner of things suggested in blog posts and SO posts... creating DSNs in ODBC Administrator, creating a ~/.odbc.ini, attempting to use unixODBC (which didn't work with PyODBC), specifying a connection string instead of keyword args, etc. I also produced a trace file through iODBC, which I have pasted here, but I couldn't glean any more information from it than from the error message.

(I should mention that I am tunneling the connection to SQL Server over SSH with the line LocalForward localhost:1433 production.someinstitution.edu:1433 in my ~/.ssh/config, since my IT department has limited me to connect only from the production server's IP. It works for a GUI client (SQuirreLSQL) so I assume the forwarding is correct.)

4

1 に答える 1

3

You should use 'port' parameter in connection string in case of DSN-less connection.

Otherwise your port could be specified in your DSN or driver config (odbc.ini and freetds.conf respectively)

于 2012-08-15T19:41:42.413 に答える