设置Rails以使用sqlserver

时间:2008-09-24 23:17:13

标签: sql-server ruby-on-rails windows ruby

好的,我按照在Vista计算机上设置ruby和rails的步骤进行操作,并且在连接数据库时遇到问题。

database.yml

的内容
development:
  adapter: sqlserver
  database: APPS_SETUP
  Host: WindowsVT06\SQLEXPRESS
  Username: se
  Password: paswd

从myapp目录运行rake db:migrate

----------
rake aborted!
no such file to load -- deprecated

ADO

我安装了dbi 0.4.0并在

中创建了ADO文件夹

C:\Ruby\lib\ruby\site_ruby\1.8\DBD\ADO

我从dbi 0.2.2获得了ado.rb

我还应该考虑修复连接数据库的问题?请不要告诉我使用MySql或Sqlite或Postgres。

**** **** UPDATE

我已经从--source = http://gems.rubyonrails.org安装了activerecord-sqlserver-adapter gem

仍然无法正常工作。

我已通过使用凭据登录SQL Management Studio验证我可以连接到数据库。


rake db:migrate --trace


PS C:\Inetpub\wwwroot\myapp> rake db:migrate --trace
(in C:/Inetpub/wwwroot/myapp)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
no such file to load -- deprecated
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
C:/Ruby/lib/ruby/site_ruby/1.8/dbi.rb:48
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/kernel/requires.rb:7:in `require_library_
or_gem'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnin
gs'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/kernel/requires.rb:5:in `require_library_
or_gem'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-1.0.0.9250/lib/active_record/connection_adapters/sqlserver
_adapter.rb:29:in `sqlserver_connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specificatio
n.rb:292:in `send'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specificatio
n.rb:292:in `connection='
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specificatio
n.rb:260:in `retrieve_connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specificatio
n.rb:78:in `connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:408:in `initialize'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:373:in `new'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:373:in `up'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:356:in `migrate'
C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/tasks/databases.rake:99
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:621:in `call'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:621:in `execute'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:616:in `each'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:616:in `execute'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:582:in `invoke_with_call_chain'
C:/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:575:in `invoke_with_call_chain'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:568:in `invoke'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2031:in `invoke_task'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `top_level'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `each'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `top_level'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2048:in `standard_exception_handling'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2003:in `top_level'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:1982:in `run'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2048:in `standard_exception_handling'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:1979:in `run'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.2/bin/rake:31
C:/Ruby/bin/rake:19:in `load'
C:/Ruby/bin/rake:19
PS C:\Inetpub\wwwroot\myapp>

6 个答案:

答案 0 :(得分:5)

我昨天遇到了同样的问题。显然,“已弃用”是一个宝石,所以你想运行“gem install deprecated”来获取并安装最新版本。祝你好运。

答案 1 :(得分:3)

我在Windows Server 2008上使用了ODBC数据源和SQL Server适配器,而不是在远程实例上运行的SQL Server 2000。

安装SQL Server适配器

gem.bat install activerecord-sqlserver-adapter
  Successfully installed deprecated-2.0.1
  Successfully installed dbi-0.4.1
  Successfully installed dbd-odbc-0.2.4
  Successfully installed activerecord-sqlserver-adapter-2.2.22
  4 gems installed

创建ODBC数据源

  • 类型:SQL Server
  • 名称:rails_development
  • 描述:rails_development
  • 服务器:SERVER
  • SQL身份验证(sa / 12345)
  • 默认数据库:DATABASE

设置database.yml

development:
    adapter: sqlserver
    mode: odbc
    dsn: rails_development
    username: sa
    password: 12345

<强> YMMV

一些有用的链接:

答案 2 :(得分:2)

您安装了SQL Server适配器吗?

gem install activerecord-sqlserver-adapter --source=http://gems.rubyonrails.org

答案 3 :(得分:2)

如果您使用的是64位计算机,则有两个ODBC管理员程序,一个用于32位,一个用于64位。 activerecord-sqlserver-adapter查找使用32位版本设置的DSN。

答案 4 :(得分:1)

答案 5 :(得分:0)

我也遇到过这个问题。还有另一项工作。 您可以从控制面板 - &gt; admin tools-&gt; Odbc为app db创建DSN。 Database.yml文件应如下所示:

adapter: sqlserver
mode: odbc
dsn: DSN_NAME
host: localhost
database: App_development
username: uname
password: password

我尝试使用已弃用的gem,没什么用处。 我曾尝试安装一个无用的ADO适配器。