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

编程入门 行业动态 更新时间:2024-10-28 20:16:36
本文介绍了Rails + SQL Server:在database.yml 中放什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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.

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

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

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

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

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

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

development:
  adapter: sqlserver
  dsn: myDsn
  mode: odbc

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

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.]

我的 database.yml 文件中是否遗漏了什么?

Am I missing something in my database.yml file?

更新:我尝试使用

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

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

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.

推荐答案

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

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

也许这个 SO Q&A 会帮助你:连接从 Windows 到 SQL Server 2005 的 rails 应用程序

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

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

Also see connectionstrings for general help with connection strings.

这篇关于Rails + SQL Server:在database.yml 中放什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 20:53:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1123466.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SQL   Rails   Server   yml   database

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!