Disclaimer : I’m not a Linux Expert, and I’m sure that doing everything as root is bad, just like doing everything as a Domain Admin account is bad.
Having seen that the CTP version of the Microsoft SQL Server ODBC Driver for Linux has been released, I thought that it would be an interesting thing to play with. Particularly since it might be something I’ll interact with using C++.
Getting Ready
Officially, it’s supported on Red Hat Enterprise Linux, but I’ve not got that, and you have to pay for it (not much, but still). Having downloaded Fedora 16,installed it in a VM (VMWare Workstation), and fired it up, I needed to install a number of prerequisites.
Using the Add/Remove Software option in Applications –>System Tools, I installed these Packages:
- Development Libraries
- Development Tools
I also needed to install wget. Type it into Filter box, tick the box against the result and click Apply.
Then download the driver from here: http://www.microsoft.com/download/en/details.aspx?id=28160
Note, that you’ll also need the unixODBC Driver manager, and the current version is 2.3.1. I couldn’t get that working, but 2.3.0 does work, and is available to download here (unixODBC-2.3.0).
Installing it
To get everything to work, I downloaded the files into the Downloads directory, and follow the instructions on the MS Downloads page (copied below, and with an item (3) added by me to make life easier).
To install the driver manager:
|
Next up, we need to install the driver, again, follow the instructions from the MS Download page (copied here):
To install the driver:
|
Resolving library issues
That then completed the installation. However, I did get a couple of issues when running sqlcmd. These issues were down to different versions of a couple of Linux SSL libraries being installed, rather than the expected version. Having had a root (pun not intended) around, the issues were resolved by adding a couple of symbolic links (kind of like shortcuts, kind of…), by doing this:
ln –s /lib64/libcrypto.so.1.0.0.e /lib64/libcrypto.so.6 ln –s /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6 |
Time to Play!
As if by magic, I can now query a SQL Server database, from Linux!
This was surprisingly straightforward I thought. My next thoughts will be to see if I can communicate with it from code (C++ since it’s Linux ).
Update – 26/1/2012
It’s been requested that I post the odbc.ini and odbcinst.ini files I used. These are shown below, and are unchanged by me.
ODBC.INI
<empty file>
ODBCINST.INI
[SQL Server Native Client 11.0]
Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
Driver=/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1720.0
UsageCount=1
Hi
I have two questions :
1) I thought the sql native client drivers are only supported for RHEL 5.x (not even for RHEL 6) is that true , considering that you build and tested it successfully with fedora 16 (which are more on the line with rhel6). Atleast this was true for SQL native client 10.0 but not sure about version 11.0
2) I am trying to build it using the same versions as you are (fc13 instead of 16) , but when i try to connect to the database I always get connection error IM004 (SQLconnect error on SQL_HANDLE… , when tested using isql ).
but can successfully connect using freetds with unixodbc. Could you also test it if you can connect to your database using isql utility .Did you face a connection problem ? Can you share how you configure your odbc.ini and odbcinst.ini .
I am trying to use the SQL native client with unixodbc because sql native client does support some more features of the sql server (not sure if its true for linux driver but definitely for windows).
Thanks
Thanks for the comment.
1: As with most things, I’d imagine that it’s supported on RHEL, but may work on other systems. I used Fedora as I’ve used it before, is a similar base to RHEL, and is free (therefore is available for anyone to get and play with).
2: I didn’t specifically make any changes to the odbc.ini or obdcinst.ini files, though I’ll do some tests and let you know.
Cheers
Sure , Thanks
I do not understand whether its a version compatibility problem or configuration problem , it would be great if you can paste snippets from both the ini files .
Also because you tested using sqlcmd utility , does one need unixODBC for that to work ? I face the problem of “unable to load SQLCMD resource file(s)” , I do see the resource files in my download but do not understand where the sqlcmd looks for the resource file when it is executed . Do you know about this .
Thanks
I’ve updated the post with the INI files (apologies for the delay in this).
With regard to the unixODBC install, you need that for the SQL Native client to install successfully, and the SQL Native client install includes the setup of SQLCMD.