You’ll need to do something like the following: tsql -S myserver -U username -P mypassword **Solution: ** Use the tsql command line program to connect to your DB. Problem: How can I tell if FreeTDS is properly installed? You can see from that error message that I’m getting errors back through unixODBC and FreeTDS. Once I dropped back and installed freetds and pydobc as outlined above, I moved on to errors like the following: ProgrammingError: ('42000', " Login failed for user 'sa'. It turns out the choice of whether to use iODBC or unixODBC happens when pyodbc is built and installed. I spent a lot of time trying to figure out how to replace iODBC with unixODBC. ![]() Despite elaborate comments found online where folks say, “iODBC works fine for me” most folks agree to use unixODBC and many have tried and failed to make iODBC work as expected. iODBC is a slightly less desirable ODBC manager than unixODBC. iODBC is the default ODBC manager which now comes with Mac OS X. **Problem: **At one point I kept getting the following type of error in Python: pyodbc.Error: ('00000', ' dlopen(, 6): image not found (0) (SQLDriverConnect)') Let me capture a few of those so hopefully future adventurers will be spared some pain. But I did learn some things along the way. OK, so if I had simply installed pyodbc properly with Macports I probably could have saved myself 4 hours of pain. So the install command is this: sudo port install py27-odbc It turns out that the Macport of pyodbc is called, confusingly, simply odbc. Then I stumbled on a discussion of using the Macports to install pyodbc. So I pulled the tar ball and spend hours yesterday trying to get pyodbc to compile and work in Mac OS X including fighting with the setup.py and trying to learn about build directories and other black magic things about Python. So I tried the following: sudo port install py27-pyodbc So, for example, Pandas is py27-pandas for the Python 2.7 version of Pandas. The naming pattern for python packages in Mac is pythonVersion-packagename. Pyodbc: ( Sept 2013 update: Macport of pyodbc is now named py27-pyodbc, the way God intended.) I didn’t think there was a Macport for pyodbc. unixODBC includes the command line tool isql which is a lot like tsql. In the debugging section I’ll comment more on using isql.įor what it’s worth, the current version as of this writing is freetds **Comes along with FreeTDS. The command line tool tsql comes with FreeTDS. The +odbc bit installs unixODBC and the +mssql and +universal bits are totally mysterious to me. I ultimatly installed FreeTDS using the following Macports command: sudo port install freetds +mssql +odbc +universal And make sure you log in using the same credentials which you want to use elsewhere.įreeTDS: This is the driver which sits between the Mac ODBC layer and MS SQL Server. SQL Server: Make sure you can log into SQL Server from a windows box on the same network which you are ultimately trying to connect from. The installing process should look something like the following: ![]() Until we get all red in the face and take a step back. ![]() ![]() Of course in real life we just flail, randomly try things, and cuss a lot. It’s pretty obvious that when debugging something not working we should move through each piece and make sure each little chunk works before going to the next piece. So the things I describe below are highly biased to Macports, but much of it is highly applicable to any install method. Yes, I know Homebrew rocks and yada yada yada, but I’m not currently using Homebrew. Keep in mind that for better or worse, I’m using Macports and in some ways I really like letting Macports do the installation of things. But when I started I didn’t even understand how the pieces fit together. The diagram above shows the sort of stack I now have working. Here’s some things I didn’t understand until I fought with them for a day. So enough about why I was banging my head against the Mac ODBC wall. In addition to Python, I need to talk to corporate servers which happen to be Microsoft SQL Server. So I’m now trying to play nice with the Python guys. As part of me changing roles at the company I work for, I’ve joined a team where everyone else uses Python. At that point I was R running on Linux and soon R running on OS X. I had abandoned MSSQL more than a year ago in favor of PostgreSQL because of how much easier it is to work with PostgreSQL from a non-Microsoft stack. I just spent nearly two full days in a bare knuckle brawl with my Macbook Pro trying to get it to talk to a corporate MS SQL Server.
0 Comments
Leave a Reply. |