Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

freeTDS not using its config

Tags:

I've decided to use FreeTDS driver and unixODBC to manage the PDO connection between my LAMP-based app with a remote MsSQL database. unfortunately it appears that the driver doesn't read the freetds.conf file, nor the environmental variables set either directly via server's CLI or specified in php file by putenv() function.

now some data:

  1. as I ping the server - no packets are lost.
  2. as I telnet the server on 1433 port - the connection is established
  3. as I use the command

    TDSVER=7.0 tsql -H >IP< -p 1433 -U username 

    I am prompted to enter password and connection is established.

  4. without the TDSVER preceding the command - the connection fails with such a message:

    Error 20017 (severity 9):     Unexpected EOF from the server     OS error 115, "Operation now in progress" Error 20002 (severity 9):     Adaptive Server connection failed There was a problem connecting to the server 
  5. the tsql -C commands echos such an output:

    Compile-time settings (established with the "configure" script)                        Version: freetds v0.91         freetds.conf directory: /usr/local/etc MS db-lib source compatibility: yes    Sybase binary compatibility: no                  Thread safety: yes                  iconv library: yes                    TDS version: 5.0                          iODBC: no                       unixodbc: yes          SSPI "trusted" logins: no                       Kerberos: no 
  6. freetds.conf in the location given above has this entry:

    [MSSQL] host = >IP< port = 1433 tds version = 7.0 
  7. the ISQL also fails:

    isql -v MSSQL [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source [01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed [ISQL]ERROR: Could not SQLConnect 
  8. my odbc.ini :

    [MSSQL] Description = MS SQL Server Driver = FreeTDS TDS_Version = 7.0 Server = >IP< UID = username PWD = password ReadOnly = No Port = 1433 

I suppose the solution is really simple, but i'm just too stupid to find it...

like image 813
khartvin Avatar asked Oct 25 '12 10:10

khartvin


People also ask

Where is the FreeTDS conf located?

The default location of freetds. conf is determined by the sysconfdir option of configure. If you don't specify anything, configure's default sysconfdir is /usr/local/etc. In addition, FreeTDS will look for a file .

What is FreeTDS conf?

The freetds. conf file describes Sybase and Microsoft database servers to the FreeTDS library. It comprises sections headed by a servername, followed by a list of connection properties denoted as name-value pairs. Defaults are defined via a [global] section.


1 Answers

I spent a long time today debugging a similar problem. I had set "TDS version" in freetds.conf but it was not being used in my ODBC connection. After reading the freetds source code (connectparams.c:odbc_parse_connect_string) I discovered that:

  • If your connection string uses "SERVER=" then both freetds.conf and odbc.ini are ignored
  • If your connection string uses "SERVERNAME=" then the settings in the appropriate freetds.conf server are used
  • If your connection string uses "DSN=" then the settings in the appropriate odbc.ini DSN are used

odbcinst.ini is a red herring. FreeTDS never checks that for settings.

The settings you specify in the connection string are always respected. It also always respects the environment variables like TDSVER.

like image 111
Max Bolingbroke Avatar answered Sep 17 '22 19:09

Max Bolingbroke