FreeTDS connection problems FreeTDS connection problems windows windows

FreeTDS connection problems


Khan.

I just encountered this same situation. And I resolved this problem by adding a .freetds.conf to my home,

[global]    # TDS protocol version    tds version = 7.0 

And I know this is exactly the answer to most FreeTDS connect problems.

And this method is also provided by @Michael Berkowski.


With apologies for the five year necromancy, it appears that this error will also occur when tsql successfully connects to an open port, but the listener is some service other than SQL Server. It seems FreeTDS does not try to check if it's talking to a service other than SQL Server on login, so the error messages are cryptic. (In my case, I was using the port number for Remote Desktop.)


If you don't want to create .freetds.conf you can simply set the TDSVER Environment variable instead (e.g. on Windows to connect to SQL Server 2008 use TDS version 7.3):

set TDSVER=7.3

(for *nix use export).

See http://www.freetds.org/userguide/envvar.htm for more environment variables.

See http://www.freetds.org/userguide/choosingtdsprotocol.htm for TDS versions of different RDBMSs

You can also specify a path for a log file which can provide more information by setting the environment variable TDSDUMP, which will help troubleshoot problems and show you where config files are looked for. e.g.

set TDSDUMP=C:\temp\freetds.log

In my case setting the TDSDUMP variable revealed an error in the logs:

iconv.c:346:setting up conversions for client charset "CP1252;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C"iconv.c:348:preparing iconv for "CP1252;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C" <-> "UCS-2LE" conversioniconv.c:423:tds_iconv_info_init: client charset name "-1" invalid

Apparently FreeTDS didn't parse the charset name from the string "CP1252;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C"

I created a .freetds.conf file with the following contents:

[global]    tds version = 7.3           # version 7.3 for MSSQL 2008    client charset = UTF-8      # so that we can get unicode characters

And saved it to C:\Windows\System32\config\systemprofile\AppData\Roaming\ as suggested by the log file, which fixed the problem for me.