2012-02-23 31 views
4

連接SQL服務器我提到這個頁面紅寶石通過使用Windows身份驗證

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

我的代碼

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 

,並試圖通過Windows身份驗證連接與SQL Server的紅寶石。但我有錯誤

無法加載驅動程序 'ADO'(基本錯誤:未初始化的常量DBI :: DBD :: ADO)

任何想法?

謝謝

+0

這有幫助嗎? http://gordonotspanish.blogspot.com/2010/02/resolved-uninitialized-constant.html – ScottJShea 2012-02-24 00:39:32

回答

-1

你指的頁面是三歲。

今天,你應該使用TinyTds一種簡單的方法訪問 一個MS SqlServer的(看看Github上它)

+1

謝謝,我通過那裏看了兩個git repo https://github.com/rails-sqlserver/activerecord-sqlserver-adapter https: //github.com/rails-sqlserver/tiny_tds我仍然沒有看到一個熱門的例子來將SQL Server與受信任的connecton連接起來。你能舉個例子嗎? – icn 2012-02-24 22:09:44

+0

哦,Sry,TinyTds目前不支持Windows身份驗證 – Klaus 2012-04-16 20:23:00

0

你不需要TinyTds,我的系統:紅寶石1.9.3,紅寶石DevKit時,SQL Server 2012 ,windows 7

先安裝這些寶石;下面

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

工作腳本連接,(不知道的需要「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? 

如果直接通過SQL Server實例與反斜槓它錯誤的連接字符串,但如果它被傳遞它接受的變量

相關問題