to make perl properly handle utf-8 strings inserted and retrieved from ms sql database, freetds config must be used (the configuration with only odbc.ini is possible to make perl connect to a database, but i could not find any way to make it work with utf)
for this purpose, the entry in odbc.ini should contain “Servername”, which points to an entry in the freetds.conf. the sample configuration may look as following:
#/etc/odbc.ini
#/usr/local/etc/freetds.conf
#perl script connection string:
tips:
- use tds dump for debugging. for this, set the TDSDUMP env variable and try to connect; read debug info from the dump file:
- use tsql to debug connection. in another terminal, set the TDSDUMP variable, run
then exit, and compare information from the tsql’s dump with the script’s dump
- be careful with config files; freetds can read from /usr/local/etc/freetds or /etc/freetds.conf depending on it’s installation configuration, but will definitely use only $HOME/.freetds.conf if it exists
- and do not forget to enclose your utf-8 strings in N” in queries, otherwise ms sql server will not understand it’s utf: