Connecting to an Azure database on your Mac can be more convenient than opening a virtual machine at times, especially when you’re working with a 128gb SSD and your Windows VM isn’t on said SSD. FreeTDS to the rescue!
While it would be nice if Microsoft would opensource the Microsoft SQL Server driver for Linux, FreeTDS seems to work for my situations just fine. In order to get FreeTDS installed and connecting to Azure, you’ll need Homebrew. After you get that sorted out, open up your favorite terminal emulator and run the following:
brew install --enable-msdblib --with-unixodbc freetds
Once this is completed and freetds is compiled, you’ll want to make some changes to your
odbcinst.ini file possibly located at
/usr/local/Cellar/unixodbc/2.3.2/etc/, but the best way to be certain about where your unixodbc installation assumes its files are is to run
odbcinst -j from the terminal to check.
Once you have your
odbcinst.ini opened in your favorite text editor, add the following:
[ODBC] Trace = No TraceFile = /tmp/odbc.log [FreeTDS] Driver = /usr/local/lib/libtdsodbc.so UsageCount = 1
If something goes awry, you can try debugging the situation with Trace = Yes later.
At this point, you have a driver installed named FreeTDS but no data sources configured. Go back to your text editor and open up the file
~/.odbc.ini or use the SYSTEM DATA SOURCES file that was given when you ran
odbcinst -j. Add the following to the file you just opened:
[AZURE] Description = My MS SQL server on Azure Driver = FreeTDS Server = XXXXXXXXX.database.windows.net Database = XXXXXXX Port = 1433 TDS_Version = 7.2
Change the Server and Database options to match your own. Notice the TDS_VERSION, this option is key to connecting to Azure SQL Server instances since Azure doesn’t seem to accept connections for any protocol versions 7.0 or less.
At this point, you should be able to connect to your database via the isql tool:
isql -v AZURE MYUSERNAME MYPASSWORD
If something isn’t working, make sure to enable the ODBC Tracing and check that log. Also, verify you’ve added your ip to the Allowed IP Addresses section under the Configure tab once you’ve selected your SQL Database Server in the Azure management portal.