0% found this document useful (0 votes)
113 views8 pages

Configure Linux ODBC Connections For MS SQL - Save Lono

This document provides instructions for configuring ODBC connections from Linux to Microsoft SQL Server. It describes installing the necessary ODBC and TDS packages on Fedora 10. It then guides configuring the key configuration files - odbc.ini, odbcinst.ini and freetds.conf - to define the driver, server name and TDS protocol settings. Finally, it demonstrates successfully connecting to the MS SQL server using the isql command-line tool. The goal is to enable Linux applications like Asterisk PBX or PHP scripts to remotely query the MS SQL database.

Uploaded by

avijaycse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views8 pages

Configure Linux ODBC Connections For MS SQL - Save Lono

This document provides instructions for configuring ODBC connections from Linux to Microsoft SQL Server. It describes installing the necessary ODBC and TDS packages on Fedora 10. It then guides configuring the key configuration files - odbc.ini, odbcinst.ini and freetds.conf - to define the driver, server name and TDS protocol settings. Finally, it demonstrates successfully connecting to the MS SQL server using the isql command-line tool. The goal is to enable Linux applications like Asterisk PBX or PHP scripts to remotely query the MS SQL database.

Uploaded by

avijaycse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

How to Configure Linux ODBC Connections for MS SQL | Asterisk | Save... http://www.savelono.com/linux/how-to-configure-linux-odbc-connections...

Asterisk
Linux
News
Scripts
Windows
Home

Save Lono
Linux Stuff, IT News, and Open Source Software
Jun

07
2009

How to Configure Linux ODBC Connections for MS SQL

Last week at work(VoiceIP


Solutions) I did some research for Asterisk PBX integration with Microsoft CRM. The customer likes open
source Asterisk because of the cost savings, but they requires screen pop-ups, and click to dial from their
Customer Relationship Management software. So while my manager worked on the TAPI middleware, I was
charged with figuring out how to connect to the MS SQL database. This article was prompted by a desire to
connect an Asterisk PBX to MS SQL, but the tutorial applies to Apache, Postfix, CRM, PHP or any Linux app
that needs to do a remote query. Also, while the focus of this article is aimed at MS SQL the same steps(with a

1 of 8 7/18/2013 4:45 PM
How to Configure Linux ODBC Connections for MS SQL | Asterisk | Save... http://www.savelono.com/linux/how-to-configure-linux-odbc-connections...

few tweaks) can be used for connecting to Postgre, Sybase, MySQL, etc…

I’m a lot more famalier with MySQL & PostgreSQL, but MS SQL I haven’t touched since I had the silly notion
about 10 years ago to become a Windows 2000 MCSE. Incidently, I never did take the exams, because I was a
broke student at the time and I was becoming increasingly interested in Linux and Cisco.

The logical choice is to use the UNIX ODBC driver. ODBC stands for Open Database Connectivity. ODBC is a
well documented set of API’s that is available on many platforms. However, their are subtle differences in it’s
implentation and the protocols that run at application layer. In other words ODBC is encapsulated when making
calls to a database over a network (in this case, the TDS protocol).

I did some googling and found a number of incomplete tutorials for connecting Linux to MS SQL. This article is
intended to clarify some common configuration errors and will present you with example files. For my
demonstration I’m running Fedora 10 with the latest updates as of this writing. This article assumes you have a
working MS SQL datebase with the proper user permissions in mixed mode. I put this one in bold because it
stumped the MCSE database guy for a while.

Again, I want to point out I’m not a Microsoft DBA and will likely not be able to help you on that side of the
configuration. Also, there are many versions of SQL out there and the syntax to pull data differs slightly from
one version to the next. So you may need to do a little research to make the proper pulls.

The Goals of this Post:

- install ODBC and TDS on Fedora 10

- verify TDS can login into MS SQL server

- configure odbcinst.ini, odbc.ini and freetds.conf configuration files

LAB: Setup ODBC/TDS for connecting to MS SQL

We will start by using yum to install the nessasary packages. All the nessary packages should be available in the
Fedora/Unbuntu repositories

[root@mattop1 ~]# yum list unixodbc*


Loaded plugins: refresh-packagekit
Installed Packages
unixODBC.i386 2.2.12-9.fc10 installed
unixODBC-devel.i386 2.2.12-9.fc10 installed

[root@mattop1 ~]# yum list freetds*


Loaded plugins: refresh-packagekit
Installed Packages
freetds.i386 0.82-4.fc10 installed
freetds-devel.i386 0.82-4.fc10 installed
freetds-doc.i386 0.82-4.fc10 installed

After these packages are installed we should be able to use freetds to test authentication network authentication
with the MS SQL server. If you can’t authenticate there is no point in going to the trouble to configure ODBC.
If you get errors check the MS SQL logs on the Windows server. By default remote terminal connections are
turned off. So remember to turn your MS SQL server to ‘mixed mode’, and restart the service. Then create a
windows user with permissions to access the database. Now TDS is ready to go!

2 of 8 7/18/2013 4:45 PM
How to Configure Linux ODBC Connections for MS SQL | Asterisk | Save... http://www.savelono.com/linux/how-to-configure-linux-odbc-connections...

[root@mattop1 ~]# tsql -S your.server.com -p 1433 -U WINDOWS-SQL-USERNAME -P PASSWORD


locale is “en_US.UTF-8″
locale charset is “UTF-8″
1>

If you made it this far you are just a few steps away from success. Our last task is to configure the freetds.conf,
odbc.ini, and the odbcinst.ini. Many help articles on the web suggest using the ‘ODBCConfig’ utility. Don’t
waste your time! Again I resort to using bold! The ODBCConfig utility sucks. The interface takes more time to
explain than just manually editing the files.

Save yourself some trouble and hand edit the files!

Now that we have avoided this pitfall we can get to business. Launch your favorite text editor and open the
/etc/odbc.ini file. On Fedora/Red Hat systems this would be the /etc/ directory.

odbc.ini

This is important, the ‘Driver field refers to ‘/etc/odbcinst.ini’ context named ‘[ms-sql]‘. The driver
information is pulled from that file. The ‘Servername’ field refers to the ‘/etc/freeItds.conf’ context that I also
named ‘[ms-sql]‘. This threw me off for a couple days, as many posts online fail to mention this. If either of
these are lines in ‘odbc.ini’ are misconfigured you will see an error like this:

3 of 8 7/18/2013 4:45 PM
How to Configure Linux ODBC Connections for MS SQL | Asterisk | Save... http://www.savelono.com/linux/how-to-configure-linux-odbc-connections...

[root@mattop1 ~]# isql -v odbc-test Your-Username Your-Password


[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect
[root@mattop1 ~]#

Now we have to define the location of the ODBC drivers in the ‘/etc/odbcinst.ini’ file. Keep in mind that actual
path of the odbc/tds drivers may differ between Linux distro’s.

odbcinst.ini

The ‘odbcinst.ini’ file simply directs the odbc.ini file to the appropriate driver. Above you can see that I have an
entry for Postgre and MS SQL. Our last Step is to configure the freetds.conf file.

Freetds is the open source version of the Tabular Data System protocol. TDS is the application layer protocol to
connect ODBC over networks. Different SQL server may require a different version of the freetds protocol.
This doesn’t require a different software package, you can specify in the ‘/etc/freetds.conf’ file what version to
use. In most cases ‘tds version = 7.0′ should work. See below.

4 of 8 7/18/2013 4:45 PM
How to Configure Linux ODBC Connections for MS SQL | Asterisk | Save... http://www.savelono.com/linux/how-to-configure-linux-odbc-connections...

freetds.conf

The final step is connecting to the remote MS SQL server. For this we use the ‘isql’ command.

[root@mattop1 ~]# isql -v odbc-test VIPS P@ssword1234

| Connected! |

| |

| sql-statement |

| help [tablename] |

| quit |

| |

+—————————————+

SQL>

With a little luck, you should get the MS SQL CLI. Just a reminder, the ‘odbc-test’ portion of the ‘isql’
command was defined in the ‘odbc.ini’ file. The ‘isql’ command can now be added to any script(PHP,
BASH,etc…) for dipping into a database. I hope this helps someone else please comment if you have any
suggestions or questions.

Configuration File Links:

/etc/odbc.ini

/etc/odbcinst.ini

/etc/freetds.conf

Other Useful Links:

5 of 8 7/18/2013 4:45 PM
How to Configure Linux ODBC Connections for MS SQL | Asterisk | Save... http://www.savelono.com/linux/how-to-configure-linux-odbc-connections...

http://www.linuxjournal.com/article/6636

http://freetds.org/

If you like this article tell Google!!

APC Back UPS


www.apcindiastore.com
Buy from the APC Official Site. Best Price with 2 Years Warranty!

Written by mattb in: Asterisk,Asterisk Post,Linux,MySQL,Scripts | Tags: and no default driver specified, and no
default driver specified [ISQL]ERROR: Could not SQLConnect, Asterisk, configuration errors, CRM, crm php,
customer relationship management, customer relationship management software, Data source name not found,
Fedora 10, freetds, freetds.conf, how to, Linux, microsoft crm, MS SQL, ms sql database, odbc, odbc driver,
odbc.ini, odbcinst.ini, pbx, pbx integration, savelono, screen pop, SQL, Sybase, TAPI, tds, tds version, VoiceIP,
VoiceIP Solutions, VoIp, Windows, [IM002][unixODBC][Driver Manager]Data source name not found

No Comments
RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Google helps those that help themselves...

Recommend my site to Google! : )

6 of 8 7/18/2013 4:45 PM
How to Configure Linux ODBC Connections for MS SQL | Asterisk | Save... http://www.savelono.com/linux/how-to-configure-linux-odbc-connections...

Recent Posts
Agent Auto log-off script for Asterisk
Ping Test script
How to Start Cinnamon desktop from Run Level Three on Fedora 16
Fedora 14 PHP daemon error
Asterisk: Holiday Macro

Pages
Site Map
sip.conf – agent logoff example
agents.conf – agent logoff example
extensions.conf – agent logoff example
queues.conf – agent logoff example
extensions.conf – Asterisk 1.4.23 and Queuemetrics 1.5.2
queues.conf – Asterisk 1.4.23 and Queuemetrics 1.5.2 fully support Dynamic Agent Login
odbc.ini – How To configure Linux ODBC connections for MS SQL
odbcinst.ini – How To configure Linux ODBC connections for MS SQL

7 of 8 7/18/2013 4:45 PM
How to Configure Linux ODBC Connections for MS SQL | Asterisk | Save... http://www.savelono.com/linux/how-to-configure-linux-odbc-connections...

freetds.conf – How To configure Linux ODBC connections for MS SQL


Polycom 501 XML configuration file Example
odbcinst.ini – How to use the ODBC driver to Connect to MySQL database in Fedora 10
odcb.ini – How to use the ODBC driver to Connect to MySQL database in Fedora 10
Voice Provision .04

SaveLono Site Map!!!!

8 of 8 7/18/2013 4:45 PM

You might also like