0

I've followed these instructions (exchanging the dummy variables where necessary) and can't get pass the step where you run with isql. The FreeTDS driver seems to be working (though instead of getting a CLI it just starts counting upwards), but I get the same error every time with the isql step:

[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect

A coworker followed the instructions and it worked. I'm trying this on my personal computer, and I've been fairly cavalier with my installs (using Anaconda and Homebrew), is it possible that this is an install issue and something's not getting linked?

My strongest hunch is that isql isn't linking MSSQL_DSN to the config

James Kelleher
  • 1,957
  • 3
  • 18
  • 34
  • If you tested with `tsql` and it starts counting upward, that means it isn't connecting. First, let's make sure you can connect: `telnet your.server.com 1433` from the Terminal. If it connects, you're good. If not, you've most likely got a firewall blocking. Next, try `tsql -C` and make sure you're using the proper `freetds.conf` file. Also, check the version of FreeTDS you are running, and make sure the `tds version` you're using is supported by the version of FreeTDS. If you're using 0.91 (included with many distros), try `7.1` or `7.2` for `tds version`. – FlipperPA Jul 22 '17 at 21:44

1 Answers1

0

You can try the following steps:

Follow the instructions given in https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX

Now, there are few additional steps and hacks if isql/osql doesn't work(assuming tsql is working properly). Each of the steps listed below is an outcome of debugging the osql error message.

At one or more steps, you may require additional root privileges. Grant them as necessary and revoke once the pyodbc connectivity is achieved.

  1. The files odbc.ini and odbcinst.ini should also be present in /Users//etc, apart from the official doc specified location.

  2. There should be a copy of odbcinst.ini in /(root directory) as well.

  3. The file freetds.conf should be present in /usr/local/etc directory.

  4. If you are using SQL server 2014 and above, tds version should be set to 7.4. Do not set tds version to 8 since it is just an alias for 7.1.

  5. Check whether the file /usr/local/lib/libtdsodbc.so has execution privileges. If not, grant 766/777(in worst case) privilegs via chmod.This step is crucial for running osql/isql and in turn pyodbc connection from python.

After these steps, re-check once the contents of odbc.ini, odbcinst.ini and freetds.conf and confirm they are as per the documentation (https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX)

Run isql/osql.

If everything works fine now, you are all set up to connect to SQLServer from python.The following snippet shows the basic connection process.

import pyodbc

connection = pyodbc.connect('DSN=MYMSSQL;UID=;PWD=) cursor = connection.cursor() result = cursor.execute("select @@VERSION").fetchall() print(result) cursor.close() connection.close()