Connect to MS SQL Server using Python on Mac

Introduction

I wanted to connect to an MS SQL server database using Python from my Mac laptop. I struggled a bit but eventually I had a working solution. I thought it can be useful so I am sharing it…

Steps

  • Make sure you have brew installed on mac. If not, you can get it from here.
  • brew update
  • brew install unixodbc freetds
  • To find where freetds.conf is located (ex. ~/homebrew/etc) type…

  • Create a symbolic link if it does not exist

  • Open the following file…

  • Go to the end of the file and copy the snippet below then exit and save

  • To find where odbc.ini and odbcinst.ini are located type…

  • Edit odbcinst.ini and copy the following…

  • Create symbolic link if it does not exist

  • Edit odbc.ini and copy the following snippet…

  • Check connection:

  • if you provide the correct user name and password. You should get something like…

  • Make sure you have virtualenv installed, if not you can do so by…

  • Create a virtual env…

  • Install pyodbc

  • Create a new python file and add the following snippet…

  • Run from the terminal…

  • If everything is ok you should get something like…

That is all for today. Thanks for visiting.

Tags:,
One Comment

Add a Comment

Your email address will not be published. Required fields are marked *