Python and pyobdc error: [unixODBC] [FreeTDS] [SQL Server] Cannot connect to data source (0) (SQLDriverConnect)

I am trying to use pyodbcpython to connect to MSSQL server. Python 2.7 runs on the development system using Anaconda virtualenv on Mac OSX Yosemite.

Execution of the following code

connection = pyodbc.connect('DRIVER={FreeTDS};SERVER="192.168.1.106";PORT=1433;DATABASE=myDB;UID=myUsername;PWD=myPassword;CHARSET=UTF8;TDS_Version=8.0;')

gives an error

[unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)

Why does this cause an error?


I also installed unixodbcand freetds --with-unixodbcthrough homebrewand configured the following

~ / .odbc.ini

[odbc1]
Driver = FreeTDS
Server = 192.168.1.106
Port   = 1433
TDS_Version = 8.0

/usr/local/etc/freetds.conf

[global]
    # TDS protocol version
    tds version = 8.0

pyodbc the package is installed manually using python setup.py install

Check

$ isql odbc1 myUsername myPass
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> 

Check FreeTDS

$ tsql -S sqlserver -U myUsername -P myPassword
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> 

There is also no problem connecting to the MS SQL server using Navicat software

How to fix a connection problem?

+4

Source: https://habr.com/ru/post/1609225/


All Articles