简体   繁体   English

使用Windows身份验证连接ruby连接SQL Server

[英]ruby connect SQL server by using Windows authentication

I referred this page 我提到了这个页面

http://www.codecapers.com/post/using-ruby-with-sql-server.aspx 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 by Windows authentication . 并尝试通过Windows身份验证将ruby与sql server连接。 But I got error 但是我有错误

Unable to load driver 'ADO' (underlying error: uninitialized constant DBI::DBD::ADO) 无法加载驱动程序“ ADO”(根本错误:未初始化的常量DBI :: DBD :: ADO)

Any idea? 任何的想法?

Thanks 谢谢

you don't need TinyTds, my system: ruby 1.9.3, ruby DevKit , sql server 2012, windows 7 您不需要TinyTds,我的系统是:ruby 1.9.3,ruby DevKit ,sql server 2012,windows 7

install these gems first; 首先安装这些宝石;

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

working script below connects, (not sure about the require 'pp') 下面的工作脚本进行了连接,(不确定是否需要“ pp”)

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 into the connection string with a backslash it error but if passed as a variable it accepts 如果您将SQL Server实例直接传递给带有反斜杠的连接字符串,则返回错误,但如果作为变量传递,则接受

The page you are refering to is three years old. 您所指向的页面已有3年历史了。

Today you should use TinyTds for an easy way accessing A MS SqlServer ( look at Github for it ) 今天,您应该使用TinyTds来访问MS SqlServer的简便方法(请参阅Github)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM