0

I'm trying to use the pyodbc library on my MacBook Pro running Mac OS X Mojave.

However, I can't install the driver properly. I've followed the pyodbc guide here but I can't reproduce the results on the page.

I am able to run the command :

tsql -S mydb -U myuser -P mypassword

I successfully get results from my database. However, when I proceed with the configurations on odbcinst.ini and odbc.ini and then try to run the command:

isql mydb myuser mypassword -v

The error message I get is:

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

Here are the contents of my odbcinst.ini file:

[FreeTDS]
Description=FreeTDS Driver for Linux & MSSQL
Driver=/usr/local/Cellar/freetds/1.00.109/lib/libtdsodbc.0.so
FileUsage=1

[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/usr/local/Cellar/msodbcsql17/17.2.0.1/lib/libmsodbcsql.17.dylib
UsageCount=1

Here are the contents of my odbc.ini file:

[mydb]
Description = FreeTDS
Driver = F
Servername = myServer
Server = servername
Port = 1433
UserName = SA
Password = pwd
Trace = Yes
Database = dbname

I'm not sure what I'm doing right. I've ensured that all the drivers are in the directories listed in the odbcinst.ini file.

Thanks in advance for your help. :)

Edit - 1 I forgot to mention earlier that when I was installing freetds with brew, I could not use the command specified in the instructions.

The instruction provides the command:

brew install freetds --with-unixodbc

However, when I used that command, I get the following error:

Error: invalid option: --with-unixodbc

So, I installed freetds without the --with-unixodbc extension.

Could this be a reason why?

Sathya
  • 155
  • 1
  • 5
  • 18
  • Can you run `odbcinst -j` to confirm the locations of your odbcinst.ini and odbc.ini files? – Gord Thompson Feb 05 '19 at 12:01
  • unixODBC 2.3.7 DRIVERS............: /usr/local/etc/odbcinst.ini SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources USER DATA SOURCES..: /Users/MAC/.odbc.ini SQLULEN Size.......: 8 SQLLEN Size........: 8 SQLSETPOSIROW Size.: 8 – Sathya Feb 05 '19 at 12:40
  • I did check this previously, and the .ini file locations were the same as specified in the command. However, I found those files to be shortcuts so I tried to specify the exact file path but it still didn't work. Now that I'm taking another look at the command result, I'm noticing the location for user data source and found no ini file in that location. Could that be the reason? – Sathya Feb 05 '19 at 12:42
  • No, a missing User Data Sources file should not cause a problem if the System Data Source is configured correctly. Note that in your (System) DSN you should specify *either* `SERVERNAME` *or* `SERVER`, not both. (`SERVERNAME` points to an entry in freetds.conf. `SERVER` is a literal DNS name or IP address.) – Gord Thompson Feb 05 '19 at 14:48
  • Thanks @GordThompson, I've removed the SERVERNAME key and am using the SERVER key only with my DB Server IP address. But I'm still getting the same error. – Sathya Feb 05 '19 at 15:05
  • @GordThompson, I added in my question a little glitch I had while installing freetds that I hadn't mentioned earlier. I couldn't install it with the "--with-unixodbc" . Could this be a reason? If so, how can I install the driver with the extra command? – Sathya Feb 05 '19 at 15:11
  • Instead of using the (possibly [outdated](https://github.com/mkleehammer/pyodbc/issues/519#issuecomment-460400978)) instructions in the pyodbc wiki you might have better luck with Microsoft's Linux version of the ODBC driver using the instructions [here](https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017#os-x-1011-el-capitan-macos-1012-sierra-and-macos-1013-high-sierra). – Gord Thompson Feb 06 '19 at 00:42
  • I did consider using Microsoft's driver as well and tried using their instructions. Like with installing freetds, when I tried installing the microsoft driver, I got an error saying --no-sandbox is an invalid option. So, I installed the driver without the --no-sandbox option but still got the same error. Could that be why? – Sathya Feb 06 '19 at 01:09

0 Answers0