Connecting to Sql Server from Ubuntu using ODBC

I am attempting to connect to Microsoft SQL Server from Ubuntu using Microsoft’s ODBC driver (RedHat6/msodbcsql-11.0.2270.0.tar.gz). I followed the procedure described here for installation:

I have successfully connected to my database from the command line using sqlcmd.

I updated /etc/odbc.ini with the following:

[ODBC Driver 11 for SQL Server]

Description=Microsoft ODBC Driver 11 for SQL Server




I upgraded to Yii 1.1.16 which is noted as supporting ODBC:

I believe the problem is in my db configuration:

		'db' => array (


            'driverName' => 'sqlsrv',

            'connectionString' => 'odbc:Driver={ODBC Driver 11 for SQL Server};Server=<server>;Database=<database>',

            'username' => '<username>',

			'password' => '<password>',

			'charset' => 'utf8',


Does anyone have any recommendations?

Thanks, Steve

And the error I am seeing is:

 CDbConnection failed to open the DB connection: could not find driver


I was able to get access to SQL Server via ODBC working.

The driverName parameter needed to be set to mssql and I updated my odbc.ini and odbcinst.ini files.



Driver=ODBC Driver 11 for SQL Server

Description=Microsoft ODBC Driver 11 for SQL Server



Trace                   = yes

TraceFile               = /tmp/odbctracefile.log

# disable tracing in production!

[ODBC Driver 11 for SQL Server]

Description             = Microsoft ODBC Driver 11 for SQL Server

Driver                 = /opt/microsoft/msodbcsql/lib64/

Threading               = 1

UsageCount              = 3

Change to the db field in config/main.php:

                'db' => array (

            'driverName' => 'mssql',

            'connectionString' => 'odbc:Driver=ODBC Driver 11 for SQL Server;Server=<server>;Database=<database>',

            'username' => '<username>',

                        'password' => '<password>',

                        'charset' => 'utf8',




These changes allowed the connection to SQL Server to complete, but I received a "SQLSTATE[22001]: String data, right truncated" Error when attempting to read the Message table. This I beleive is due to an issue with the php pdo_odbc extension on 64-bit systems:

I resolved this problem by installing the found here:

This solution has the same issues I had using FreeTDS. No support for NVARCHAR(MAX). I am going to check out the easy soft driver, but will likely switch back to FreeTDS.

I was unable to get unicode to work with FreeTDS and I had a number of problems with the easy soft driver, so it looks like the Microsoft ODBC driver is the winner.

Make sure you enable schema caching when using Sql Server (schemaCachingDuration flag). The Sql Server schema queries are excruciatingly slow.

The product documentation on SQL Server ODBC Driver page of DataDirect can help you fix this.

For some reason I couldn’t add a link, but please feel free to access sql server ODBC page by datadirect