Ruby-on-rails 如何修复 [unixODBC][Driver Manager] 未找到数据源名称且未指定默认驱动程序 (ODBC::Error)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21237678/
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-02 23:14:44  来源:igfitidea点击:

How to fix the [unixODBC][Driver Manager]Data source name not found, and no default driver specified (ODBC::Error)

ruby-on-railsruby-on-rails-3odbcunixodbc

提问by Clone

/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver_adapter.rb:455:in `initialize': IM002 (0) [unixODBC][Driver Manager]Data source name not found, and no default driver specified (ODBC::Error)

I have working copy of my app but suddenly overnight I left my system like that and this error started surfacing. Can anyone tell how to fix this one please?

我有我的应用程序的工作副本,但突然一夜之间我就这样离开了我的系统,这个错误开始出现。谁能告诉如何解决这个问题?

回答by bohica

There is no definitive answer to your question since you gave us nothing to work on.

你的问题没有明确的答案,因为你没有给我们任何工作。

However, the possible reasons for this are:

但是,造成这种情况的可能原因是:

  1. the DSN you specified could not be found in your user or system odbc.ini files Run odbcinst -j to find where those files are Has someone changed/removed them?

  2. You set ODBCINI env var or ODBCSYSINI env var to point unixODBC at the location of your odbc.ini and odbcinst.ini files and now they are not set (or changed).

  3. Someone has removed or moved your ODBC driver

  4. You normally run your code as user A and now you are running it as user B and you are using user datasources or set ODBCINI env var.

  1. 在您的用户或系统 odbc.ini 文件中找不到您指定的 DSN 运行 odbcinst -j 以查找这些文件的位置 是否有人更改/删除了它们?

  2. 您将 ODBCINI env var 或 ODBCSYSINI env var 设置为将 unixODBC 指向 odbc.ini 和 odbcinst.ini 文件的位置,但现在它们未设置(或更改)。

  3. 有人删除或移动了您的 ODBC 驱动程序

  4. 您通常以用户 A 身份运行代码,现在以用户 B 身份运行代码,并且您正在使用用户数据源或设置 ODBCINI 环境变量。

... probably others but if you'd given us better information we wouldn't have to guess.

...可能是其他人,但如果你给了我们更好的信息,我们就不必猜测了。

回答by tufelkinder

You should start by setting up and configuring FreeTDS. Here is a sample configurations from my files, but I'm sure other variants will work also. One difference is that I'm using Django, but the result below still worked eventually, but it works much better with SQL authentication than with Windows Authentication.

您应该从设置和配置 FreeTDS 开始。这是我的文件中的示例配置,但我相信其他变体也可以使用。一个区别是我使用的是 Django,但下面的结果最终仍然有效,但它在 SQL 身份验证中的效果比 Windows 身份验证要好得多。

From /etc/freetds/freetds.conf(use the IP of the server if DNS is not active for the server name).

来自/etc/freetds/freetds.conf(如果 DNS 对服务器名称无效,则使用服务器的 IP)。

# A typical Microsoft server
[MyServer]
        host = 10.0.0.10\path
        port = 1433
        tds version = 7.0

From /etc/odbcinst.ini

/etc/odbcinst.ini

[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

From /etc/odbc.ini

/etc/odbc.ini

[ServerDSN]
Description = "Some Description"
Driver = FreeTDS
ServerName = MyServer
Server = ip_address
Port = 1433
Database = DBNAME

Then this command connects me to the database.

然后这个命令将我连接到数据库。

tsql -S MyServer -U username@servername -P password

tsql -S MyServer -U username@servername -P password

回答by Marcelo

just a tip, in my case was not possible with Driver = FreeTDS and both variables "servername" and "server" in odbc.ini. I let only "server = ip" and "Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so", worked fine.

只是一个提示,在我的情况下,Driver = FreeTDS 和 odbc.ini 中的两个变量“servername”和“server”是不可能的。我只让“server = ip”和“Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so”,工作正常。