Richard Bucker

Connect Tcl to Sql Server

Posted at — Jun 22, 2020

SQL Server is just no fun to connect to. Sure there are choices like the TDS protocol and ODBC API the problem is that most languages implement SQL Server last. I have no idea if the issues is that TDS or ODBC are awesome or native APIs are simply too hard to implement.

While that’s all about languages it’s even worse with operating systems. For years I have been trying to deploy FreeTDS and UnixODBC and have failed time after time.

Now as the Authors of (go)[] are considering generics I’m starting to consider whether go is the language for me. But that’s a separate discussion.

Here are some steps that I used ot get my tcl app (on FreeBSD 12.1) to run a query against a remote API.



my config files


Description=<just a description>
Server=<ip or hostname>
encryption = require


  Driver = /usr/local/lib/
  Client Charset = UTF-8
  UsageCount = 1


 host = <ip or hostname>
 port = 1433
 encryption = require

my tcl test

package require tdbc::odbc
set connStr "Driver=FreeTDS;DSN=f1;UID=<dbuser>;PWD=<dbpassword>"
puts $connStr
tdbc::odbc::connection create db $connStr
db foreach rec { SELECT top 10 firstname FROM customers  } {
    puts "Found \"[dict get $rec firstname]\" in the customers table"

Running my test program

$ tclsh8.7 ss.tcl 


Now that I have this working for TCL I need to try this in (nim)[]