Ruby Connect SQL Server Using Windows Authentication

I linked to this page

http://www.codecapers.com/post/using-ruby-with-sql-server.aspx

my code

DBI.connect('DBI:ADO:Provider=SQLNCLI;Data Source=SQLSERVER001;Integrated Security=True;Initial Catalog=DB001') do | dbh | # Replace mytable with the name of a table in your database. dbh.select_all('select top 1000 * from history where type="35" ') do | row | puts row end end 

and trying to connect ruby ​​with sql server for windows authentication. But I got an error

Unable to load ADO driver (main error: uninitialized constant DBI :: DBD :: ADO)

Any idea?

thanks

+4
source share
2 answers

you don't need TinyTds, my system: ruby ​​1.9.3, ruby ​​DevKit, sql server 2012, windows 7

first set these gems;

 gem install dbi gem install dbd-odbc gem install activerecord-sqlserver-adapter 

working script below connects (not sure about 'pp' requirement)

 require 'rubygems' require 'DBI' require 'pp' server = 'XXXXX-LT0XXXX\XXX' database = 'mydatabase' conn = DBI.connect("DBI:ODBC:DRIVER={SQL Server};Server=#{server};Database=#{database};Trusted_Connection=yes") #==> sets up the connection puts conn.connected? 

if you pass the sql server instance directly to the backslash connection string, but if it is passed as a variable, it takes

0
source

The page you link to is three years old.

Today you should use TinyTds for easy MS SqlServer access (look at Github for it)

-one
source

Source: https://habr.com/ru/post/1398142/


All Articles