windows Rails + SQL Server:在database.yml 中放什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3806584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:19:31  来源:igfitidea点击:

Rails + SQL Server: what to put in database.yml?

ruby-on-railssql-serverwindows

提问by grautur

I'm trying to connect Rails to SQL Server. I installed the activerecord-sqlserver-adapter and ruby-odbc gems, but I'm not sure what to put in my database.yml file.

我正在尝试将 Rails 连接到 SQL Server。我安装了 activerecord-sqlserver-adapter 和 ruby​​-odbc gems,但我不确定在我的 database.yml 文件中放入什么。

What exactly is a DSN, and why do I need it? (Is this some windows-specific thing?)

到底什么是 DSN,我为什么需要它?(这是一些特定于 Windows 的东西吗?)

What do I do if I want to use Windows Authentication, instead of specifying a username and password?

如果我想使用 Windows 身份验证而不是指定用户名和密码,该怎么办?

I tried creating a DSN, specifying Windows NT authentication, and put the following in my config.yml:

我尝试创建一个 DSN,指定 Windows NT 身份验证,并将以下内容放入我的 config.yml:

development:
  adapter: sqlserver
  dsn: myDsn
  mode: odbc

but I get a "The specified DSN contains an architecture mismatch between the Driver and Application" error. [I tried creating the DSN from Windows/system32/odbcad32.exe as well, since a Google search said this would create a 32-bit DSN instead, but I get the same error.]

但我收到“指定的 DSN 包含驱动程序和应用程序之间的体系结构不匹配”错误。[我也尝试从 Windows/system32/odbcad32.exe 创建 DSN,因为 Google 搜索说这将创建一个 32 位 DSN,但我得到了同样的错误。]

Am I missing something in my database.yml file?

我的 database.yml 文件中是否缺少某些内容?

UPDATE: I tried using

更新:我尝试使用

development:
  adapter: sqlserver
  mode:odbc
  dsn: Provider=SQLOLEDB; Data Source=.\SQLEXPRESS; Integrated Security=SSPI

but I get a "Data source name not found and no default driver specified" error. Is it possible my Provider is not SQLOLEDB? [I don't know what a provider is or how to figure out what it's supposed to be -- I just copied it from another connection string I found.] I do know that I can connect to .\SQLEXPRESS using Windows Authentication from my actual SQL Server Management Studio program.

但我收到“未找到数据源名称且未指定默认驱动程序”错误。我的提供程序可能不是 SQLOLEDB 吗?[我不知道提供者是什么,也不知道如何确定它应该是什么——我只是从我找到的另一个连接字符串中复制了它。] 我知道我可以使用 Windows 身份验证连接到 .\SQLEXPRESS 从我的实际的 SQL Server Management Studio 程序。

采纳答案by Joe Stefanelli

A DSN is a "Database Source Name." It contains the information that an ODBC driver needs to connect to a specific database.

DSN 是“数据库源名称”。它包含 ODBC 驱动程序连接到特定数据库所需的信息。

Perhaps this SO Q&A will help you: Connect rails application to SQL Server 2005 from Windows

也许这个 SO Q&A 会对您有所帮助:从 Windows 将 rails 应用程序连接到 SQL Server 2005

Also see connectionstrings.comfor general help with connection strings.

另请参阅connectionstrings.com以获取有关连接字符串的一般帮助。