2

First of all, I know this question was asked/answered once here, but I followed the steps suggested here, and got stucked in the middle of the steps.

Before the question, I have a Python script which runs well on a CentOS server:

import pyodbc 

server = 'tcp:192.168.1.1' 
database = 'MYDB' 
username = 'username' 
password = 'password'

sqlQuery = "SELECT * FROM dbo.DB1;"

cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
cursor.execute(sqlQuery)

The same script gives me error on macOS, so I followed the nstruction in the previous link step by step, I had FreeTDS installed, and tested with tsql -S 192.168.1.1 -U username -P password. Things were fine so far.

Then I installed unixODBC with brew install unixodbc, and did the configuration as suggested:

/usr/local/Cellar/unixodbc/2.3.4/etc/odbcinst.ini

[FreeTDS]
Description=FreeTDS Driver for Linux & MSSQL on Win32
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
UsageCount=1

and..

/usr/local/Cellar/unixodbc/2.3.4/etc/odbc.ini

[MYSERVER]
Description         = Test to SQLServer
Driver              = FreeTDS
Trace               = Yes
TraceFile           = /tmp/sql.log
Database            = 'MYDB'
Servername          = 'tcp:192.168.1.1'
UserName            = 'username'
Password            = 'password'
Port                = 1433
Protocol            = 8.0
ReadOnly            = No
RowVersioning       = No
ShowSystemTables    = No
ShowOidColumn       = No
FakeOidIndex        = No   

Then I tested..

$ isql -v MYSERVER
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[08S01][unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect

also..

$ isql -v tcp:192.168.1.1 username password
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect

Back to my python script on macOS, I changed a little bit, and still could not connect to SQL server..

cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
cursor.execute(sqlQuery)

Any ideas?

Community
  • 1
  • 1
Sidney
  • 321
  • 1
  • 2
  • 13

0 Answers0