self.extended(thoughts)

Code, Entrepreneurship, Music, Life

Change Locale on OS X Snow Leopard for FreeTDS Functionality

Recently I’ve been trying to get my new unibody macbook pro connecting to SQL Server 2005 with FreeTDS. I was following the great guide from Ken Collins, author of the rails-sqlserver activerecord adapter that I use but no matter what configuration settings I edited I couldn’t get my machine to connect to the SQL Server.

When checking the event viewer on the Windows Server 2k8 box I received the following error:

1
2
3
"The login packet used to open the connection is structurally invalid; 
the connection has been closed. 
Please contact the vendor of the client library."

I was pretty sure it had to do with my locale because if that was incorrect it would make sense that the packets might be structurally invalid. My locale was set to en_US.us-ascii the default setting apparently after a clean OS X Snow Leopard install. The problem was that I couldn’t figure out how to change it. Then I ran across this archived post and I was able to temporarily change my locale by typing:

1
export LC_ALL=en_US.UTF-8

I was able to verify my locale settings by typing locale in a terminal window which yielded the following:

1
2
3
4
5
6
7
8
LANG=
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

The problem is if I opened a new terminal window my locale was back to the default ascii junk. To make this change permanent I simply had to edit my ~/.profile and add the export statement that we set earlier to the bottom of the file.

1
export LC_ALL=en_US.UTF-8

Now when I open a new window and type locale it says en_US.UTF-8 for everything. At this point I was able to continue following Ken’s guide for testing the TSQL commands and getting ruby-dbi and everything else wired up.