While I won’t digress too far from the subject, I will say that I’m excited to finally be at the point in my life where I am stable enough to step back and reflect. I’m greatly looking forward to this phase as I transition from a user of information to a creator and editor of such things.
I had a lot of trouble getting my Ubuntu 8.04 LTS Hardy workstation to talk to my SQL Server. Let me give a few details about the items involved here. My workstation runs Ubuntu 8.04; on the workstation I’m running VMware 6.04. Inside VMware I have an image which is running Microsoft Enterprise Server 2003. Ontop of this I’m running Microsoft SQL Server Enterprise 2005. This information applies to you if you are within Ubuntu or any modern user-oriented Linux and trying to connect to any type of Microsoft SQL (MSSQL) Server; my server just happens to be a VM on my workstation. We’ll start by assuming you’re MSSQL is properly setup.
Now go into Synaptic Package Manager. Search and install the following plus whatever requirements it prompts for: a) iodbc b) libiodbc2 c) libct3 d) tdsodbc e) unixodbc . Now, you might have to reboot before this works; I don’t think so but this took me a couple of occasions sporadically over two days so I can’t discount the necessity of a reboot.
Create a launcher shortcut for the iODBC interface. The executable is located: /usr/bin/iodbcadm-gtk . Go into Terminal, which I believe is the Bash-Terminal by default in Ubuntu 8.04.
Goto home directory: cd ~
Do: sudo gedit .iodbc.ini
Contents of <.iodbc.ini>
[ODBC Data Sources]ODBCdsn = ODBC Server [ODBCdsn]
Driver = /usr/lib/odbc/libtdsodbc.so
Description = ODBC Server
Trace = No
Servername = ODBC
Database = {name of your database}
[Default]
Driver = /usr/lib/odbc/libtdsodbc.so
The iODBC is basically setup. We now need to setup the FreeTDS driver which does the translation for communications purposes to MSSQL.
Do: sudo gedit /etc/freetds/freetds.conf
Append to bottom of contents of <freetds.conf>
[ODBC]host = xxx.xxx.xxx.xxx {IP address of your database server}
port = 1433 {Port of your database server}
tds version = 8.0 {Google: FreeTDS if you are on a different version of MSSQL}
Startup the iODBC shortcut we created above. Goto the User DSN tab. Click test and authenticate with a valid username and password. Everything should be working now. Now that we’ve covered the basic setup, we can always add more options such as buffer length, timeout strings, etc. All of the above can also be customized and renamed. Simply make sure that the “ODBC” in “.odbc.ini” is the same as “ODBC” in “freetds.conf”, where you can change “ODBC” to whatever name you want provided the case-sensitive similarity is maintained between the two files.
So there it is. Simple as a n00b needs it and powerful enough to be a base for power users. Enjoy!
You have a typo –
Goto home directory: cd ~
Do: sudo gedit .iodbc.ini
Contents of
should be -
Do: sudo gedit .odbc.ini
Contents of
It would be good to point out that this edits the User DSN, and the System DSN file is /etc/odbc.ini
BUt – Great information – you have helped me a lot. Thank you.
I have one last issue – when I connect to the DB using open office the queries that OO issues are formatted incorrectly. I haven’t looked into this too much yet. So far I’m happy just to have a connection.
Thanks again,
Brent Hannah
By: Brent on February 4, 2009
at 1:53 pm
how did you create your iODBC interface and where do i find .iodbc.ini? sorry am new to linux… totaly noob
By: gilad on February 26, 2009
at 6:29 am
[...] Connecting Ubuntu 8.04 to Microsoft SQL Server « A controlled skid through life. (tags: linux ubuntu php sql mssql sqlserver) [...]
By: links for 2009-04-23 « The Adventures of Geekgirl on April 23, 2009
at 10:09 pm
GOD bless you man!!
Found that post after a day of unproductive struggle.
15 minutes with your article and I’m done.
It worked with both Ubuntu and CentOS for me.
The dsn appeared on SystemDsn for me on ubuntu. CentOs has no iodbcadm-gtk, but the connections still work.
Thanks again
Robert
By: Robert on December 7, 2009
at 7:39 pm