Skip to content

Instantly share code, notes, and snippets.

@albertico
Last active October 18, 2022 16:04
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save albertico/af9691562415c415e49b to your computer and use it in GitHub Desktop.
Save albertico/af9691562415c415e49b to your computer and use it in GitHub Desktop.
A sample script for connecting to MS SQL Server database using Sequel ORM with the TinyTDS adapter.

Ruby Sequel TinyTDS MS SQL Example

A sample script for connecting to MS SQL Server database using Sequel ORM with the TinyTDS (FreeTDS) adapter.

#!/usr/bin/env ruby

require 'sequel'
require 'tiny_tds'

db_connection_params = {
  :adapter => 'tinytds',
  :host => '127.0.0.1', # IP or hostname
  :port => '1434', # Required when using other that 1433 (default)
  :database => 'dbName',
  :user => 'dbUser',
  :password => 'P@$$worD'
}

DB = Sequel.connect(db_connection_params)

tbl = DB[:tblName]

dataset = tbl.all

dataset.each do |row|
  puts row.to_s
end

Additional Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment