简体   繁体   English

错误-Ruby OCI8-错误的参数数量(0..1为2)

[英]Error - Ruby OCI8 - Wrong number of arguments (2 for 0..1)

When running this script: 运行此脚本时:

require 'oci8'

  conn = OCI8.new('username', 'password', 'tnsname')
  cursor = conn.exec('SELECT 1+1 FROM dual')

  while r = cursor.fetch()
    puts r.join(',')
  end

  cursor.close
  conn.logoff

The following error message occurs: 出现以下错误信息:

   C:/tech/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `initi
alize': wrong number of arguments (2 for 0..1) (ArgumentError)
        from C:/tech/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
:36:in `new'
        from C:/tech/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
:36:in `require'
        from C:/tech/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
:36:in `require'
        from C:/tech/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.1.5-x86-mingw3
2/lib/oci8.rb:81:in `<top (required)>'
        from C:/tech/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
:60:in `require'
        from C:/tech/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
:60:in `rescue in require'
        from C:/tech/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
:35:in `require'
        from u:/Ruby/test_oci_connect.rb:1:in `<main>'

I can use those credentials in SQLPLUS and I have both the gems and devkit installed. 我可以在SQLPLUS中使用这些凭据,并且同时安装了gems和devkit。 Can anyone assist with this issue or provide some clarity regarding the answer below? 任何人都可以协助解决此问题,或者提供有关以下答案的明确说明?

The issue is caused by a mismatch in the Oracle DLLs architecture and your Ruby installation, or your System not finding the right DLLs. 该问题是由于Oracle DLL体系结构和Ruby安装不匹配或系统找不到正确的DLL引起的。

Download the Oracle Instant Client . 下载Oracle Instant Client Its important that its the same arch that your Ruby is in, as it contains the necessary DLLs. 重要的是,它与Ruby所在的拱相同,因为它包含必需的DLL。

Unzip it somewhere on your HDD, such as: 将其解压缩到硬盘上的某个位置,例如:

C:/OracleInstantClient
Its also convenient to add both 同时添加两者也很方便
 /network/admin/sqlnet.ora /network/admin/sqlnet.ora \n/network/admin/tnsnames.ora /network/admin/tnsnames.ora 
to that folder. 到那个文件夹。

Add the Instant Client's location to your System PATH. 将Instant Client的位置添加到您的系统PATH。 You should now be able to connect without that error, provided you've added the correct connection information. 现在,只要您已添加正确的连接信息,您就应该能够连接而不会出现该错误。

I was getting the same error message, using a gem dependent on ruby-oci8 (dm-oracle-adapter for datamapper). 我使用依赖于ruby-oci8的gem(datamapper的dm-oracle-adapter)得到了相同的错误消息。 Re-ran the install as per these instructions on a fresh environment : 在全新的环境中,按照以下说明重新运行安装:

Installing instant client for ruby-oci8 为ruby-oci8安装Instant Client

Double checked the path was set correctly and restarted my ruby console. 仔细检查路径设置是否正确,然后重新启动我的ruby控制台。 And everything worked perfectly. 一切工作正常。

On the machine it didn't work on (above incorrect arguments error), I have Oracle 64 bit dlls installed for some other services. 在无法正常运行的计算机上(由于参数错误错误),我为其他一些服务安装了Oracle 64位dll。 My theory is that it was conflicting with these dlls (Ruby-oci8 needs 32bit DLLs), even though there was nothing pointing to these in the path. 我的理论是,即使路径中没有指向这些dll的文件,它们也与这些dll冲突(Ruby-oci8需要32位DLL)。

Also, if you get the warning "ext/oci8 not found" when running 'gem install ruby-oci8', let me save you some time. 另外,如果在运行“ gem install ruby​​-oci8”时收到警告“找不到ext / oci8”,请允许我节省一些时间。 In my case, this was a red herring and didn't affect the function of the gem at all. 就我而言,这是一个红色鲱鱼,根本不影响宝石的功能。

That problem doesn't seem related to OCI8 at all. 这个问题似乎与OCI8根本无关。

You are misleading us a little here by not showing the whole code. 您没有在此处显示完整的代码,从而在某种程度上误导了我们。

From your error stack trace, I can tell that you have a class that's trying to initialize but you have defined a parameter to that method and you didn't mention it when creating your object. 从错误堆栈跟踪中可以看出,您有一个正在尝试初始化的类,但是您已为该方法定义了一个参数,并且在创建对象时未提及该参数。

What this really means is that you mentioned 2 parameters where it was expecting either nothing or just one parameter. 这的真正含义是,您提到了2个参数,它期望什么都不是,或者只期望一个参数。

if you create a test.rb fiel and paste the code you show us above all by itself, does it work? 如果您创建一个test.rb文件并粘贴了您首先展示给我们的代码,那么它行得通吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM