問題描述
我正在嘗試將 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.
這篇關于Rails + SQL Server:在database.yml 中放什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!