MSSQL SQLServer FreeTDS Unicode collation error

jdavidb on 2008-08-05T19:03:51

I'm using DBD::Sybase over FreeTDS to access an MS SQLServer database and getting the following commonly-encountered error:

Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier.

This error is all over the net, seen by poor souls using Python, Borland tools, and I don't know what all else. Sadly, most of them appear to have not found a solution, other than "change the type of your column." That solution isn't available to me (if it were, I would be changing the type of my database!), so I had to keep digging until I found the real solution:

Set tds version = 8.0 in your freetds.conf file. (Using 7.0 will also correct it, but after experimentation I chose to use the latest value.)

Pages and pages of grief and agony on the net would've been dispelled if somebody had known in all the many conversations that have ensued about this message. I feel really bad when I see people asking questions over and over again and the answer never emerges.

For the record, I found the answer here after much searching, posted by "boonkit" on 2005-03-29. But I had the idea in the back of my mind this could probably be solved by changing the TDS version, and if I hadn't found it here I was going to be cycling through each possible value and trying them.

Now I want to figure out how to set this in my DBI DSN string. Until this moment, I didn't actually have to have a freetds.conf file. :)

Here's hoping that the next poor soul to encounter this error will Google for it and find the solution spelled out plainly here. For the record, if you are such a soul and are clueless about what a freetds.conf file is and where to find yours, post here to give me a ring, and assuming I'm not dead by then, I'll try to help you out. :)

Update: Experimented with the different TDS protocol versions, discovered 8.0 also works, decided to use that.