TinyTDS: Adaptive Server connection failed

I have been dealing with a gnarly bug trying to connect a Rails backend to an external Microsoft SQLServer host from inside a Docker container. Here's a few considerations for Future Me™.

  • Make sure your docker container is running in network_mode: "host". This sets your docker containers to write all network rules to your host OS networking layer, and can simplify connection to external services. Since the app I am running is small, this is appropriate.
  • Ensure that TinyTDS has your host, port, username, and password explicitly set. If you're using a concatenated connection string in your database.yml file, try splitting out your host: and port: variables so that TinyTDS has discreet values to work with.
  • Use the right FreeTDS protocol. If you're not already overriding freetds.conf, you should do so. This makes it easy to try different protocol versions without restarting your docker container or rebuilding your image.
  • Test using tsql. From inside your docker container, test your connection using tsql. It should look something like this:
# tsql -H my.host.name -U myusername -P myPassW0rd -p 1433

I hope that Future Me™ appreciates these notes as much as I would have at the start of this process.