Rails + SQL Server:在database.yml 中放什么?
我正在尝试将 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.com 以获取有关连接字符串的一般帮助.
Also see connectionstrings.com for general help with connection strings.
相关文章