on 2013 Apr 03 9:29 PM
I have been unable to make a database connection using ruby & am requesting any assistance. The database is locally run on a Windows 7 64-bit machine.
Ruby Version = ruby 1.9.3p385 (2013-02-06) [i386-mingw32]
Using dbi
require 'rubygems' require 'dbi' DBI.connect('DBI:ODBC:Agency')
Returns
from C:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect' from dbi_test.rb:4:in `<main>'
Using sqlanywhere (unable to initialize)
require 'sqlanywhere' api = SQLAnywhere::SQLAnywhereInterface.new() SQLAnywhere::API.sqlany_initialize_interface( api ) api.sqlany_init()
Returns
sqlanywhere_test.rb:65: [BUG] Segmentation fault ruby 1.9.3p385 (2013-02-06) [i386-mingw32] -- Control frame information ----------------------------------------------- c:0027 p:---- s:0109 b:0109 l:000108 d:000108 CFUNC :sqlany_init c:0026 p:0011 s:0106 b:0106 l:000093 d:000105 BLOCK sqlanywhere_test.rb:65 c:0025 p:0080 s:0104 b:0104 l:000103 d:000103 METHOD C😕Ruby193/lib/ruby/1.9.1/test/unit/assertions.rb:96 c:0024 p:0054 s:0094 b:0094 l:000093 d:000093 METHOD sqlanywhere_test.rb:64 c:0023 p:0046 s:0090 b:0090 l:000089 d:000089 METHOD C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:947 c:0022 p:0025 s:0084 b:0084 l:000083 d:000083 METHOD C😕Ruby193/lib/ruby/1.9.1/test/unit/testcase.rb:17 c:0021 p:0090 s:0080 b:0080 l:000068 d:000079 BLOCK C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:787 c:0020 p:---- s:0074 b:0074 l:000073 d:000073 FINISH c:0019 p:---- s:0072 b:0072 l:000071 d:000071 CFUNC :map c:0018 p:0124 s:0069 b:0069 l:000068 d:000068 METHOD C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:780 c:0017 p:0020 s:0061 b:0060 l:000050 d:000059 BLOCK C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:565 c:0016 p:---- s:0056 b:0056 l:000055 d:000055 FINISH c:0015 p:---- s:0054 b:0054 l:000053 d:000053 CFUNC :each c:0014 p:0053 s:0051 b:0051 l:000050 d:000050 METHOD C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:563 c:0013 p:0189 s:0045 b:0045 l:000044 d:000044 METHOD C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:746 c:0012 p:0013 s:0035 b:0035 l:000034 d:000034 METHOD C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:909 c:0011 p:0012 s:0032 b:0032 l:000023 d:000031 BLOCK C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:896 c:0010 p:---- s:0029 b:0029 l:000028 d:000028 FINISH c:0009 p:---- s:0027 b:0027 l:000026 d:000026 CFUNC :each c:0008 p:0068 s:0024 b:0024 l:000023 d:000023 METHOD C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:895 c:0007 p:0029 s:0020 b:0020 l:000019 d:000019 METHOD C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:884 c:0006 p:0022 s:0016 b:0016 l:000015 d:000015 METHOD C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:21 c:0005 p:0033 s:0012 b:0011 l:000c44 d:000010 BLOCK C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:326 c:0004 p:0036 s:0009 b:0009 l:000008 d:000008 METHOD C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:27 c:0003 p:0026 s:0006 b:0006 l:000c44 d:000005 BLOCK C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:325 c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH c:0001 p:0000 s:0002 b:0002 l:001d0c d:001d0c TOP -- Ruby level backtrace information ---------------------------------------- C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun' C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:27:in `run_once' C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun' C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:21:in `run' C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:884:in `run' C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:895:in `_run' C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:895:in `each' C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:896:in `block in _run' C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:909:in `run_tests' C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:746:in `_run_anything' C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:563:in `_run_suites' C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:563:in `each' C😕Ruby193/lib/ruby/1.9.1/test/unit.rb:565:in `block in _run_suites' C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:780:in `_run_suite' C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb:780:in `map' C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:787:in `block in _run_suite' C😕Ruby193/lib/ruby/1.9.1/test/unit/testcase.rb:17:in `run' C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:947:in `run' sqlanywhere_test.rb:64:in `setup' C:/Ruby193/lib/ruby/1.9.1/test/unit/assertions.rb:96:in `assert_nothing_raised' sqlanywhere_test.rb:65:in `block in setup' sqlanywhere_test.rb:65:in `sqlany_init' -- C level backtrace information ------------------------------------------- C:\\Windows\\SysWOW64\\ntdll.dll(ZwWaitForSingleObject+0x15) [0x77aaf8b1] C:\\Windows\\syswow64\\kernel32.dll(WaitForSingleObjectEx+0x43) [0x75771194] C:\\Windows\\syswow64\\kernel32.dll(WaitForSingleObject+0x12) [0x75771148] C:\\Ruby193\\bin\\msvcrt-ruby191.dll(rb_vm_bugreport+0xf9) [0x62e5c69d] C:\\Ruby193\\bin\\msvcrt-ruby191.dll(rb_name_err_mesg_new+0x17a) [0x62d3a856] C:\\Ruby193\\bin\\msvcrt-ruby191.dll(rb_bug+0x2f) [0x62d3b533] C:\\Ruby193\\bin\\msvcrt-ruby191.dll(rb_check_safe_str+0x1a4) [0x62dee738] [0x004011e6] C:\\Windows\\syswow64\\kernel32.dll(GetProfileStringW+0x12aa3) [0x757b003f] C:\\Windows\\SysWOW64\\ntdll.dll(RtlKnownExceptionFilter+0xb7) [0x77b074df] -- Other runtime information ----------------------------------------------- * Loaded script: sqlanywhere_test.rb * Loaded features: 0 enumerator.so 1 C😕Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/encdb.so 2 C😕Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/iso_8859_1.so 3 C😕Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/transdb.so 4 C😕Ruby193/lib/ruby/1.9.1/i386-mingw32/rbconfig.rb 5 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/compatibility.rb 6 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/defaults.rb 7 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/deprecate.rb 8 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/errors.rb 9 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/version.rb 10 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb 11 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb 12 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb 13 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/exceptions.rb 14 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/defaults/operating_system.rb 15 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb 16 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb 17 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems.rb 18 C😕Ruby193/lib/ruby/site_ruby/1.9.1/ubygems.rb 19 C😕Ruby193/lib/ruby/1.9.1/optparse.rb 20 C😕Ruby193/lib/ruby/1.9.1/minitest/unit.rb 21 C😕Ruby193/lib/ruby/1.9.1/prettyprint.rb 22 C😕Ruby193/lib/ruby/1.9.1/pp.rb 23 C😕Ruby193/lib/ruby/1.9.1/test/unit/assertions.rb 24 C😕Ruby193/lib/ruby/1.9.1/test/unit/testcase.rb 25 C😕Ruby193/lib/ruby/1.9.1/test/unit.rb 26 C😕Ruby193/lib/ruby/1.9.1/i386-mingw32/date_core.so 27 C😕Ruby193/lib/ruby/1.9.1/date/format.rb 28 C😕Ruby193/lib/ruby/1.9.1/date.rb 29 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/path_support.rb 30 C😕Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/utf_16le.so 31 C😕Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/utf_16_32.so 32 C😕Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/single_byte.so 33 C😕Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb 34 C😕Ruby193/lib/ruby/gems/1.9.1/gems/sqlanywhere-0.1.6-x86-mingw32/lib/sqlanywhere.so [NOTE] You may have encountered a bug in the Ruby interpreter or extension libraries. Bug reports are welcome. For details: http://www.ruby-lang.org/bugreport.html This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. >Exit code: 3
This is resolved - thank you Eric & Jason.
Basically I was running the 32-bit version of Ruby and did not have dbcapi.dll within the following folder structure - C:\\Program Files\\SQL Anywhere 12\\Bin32. I had another test machine (32-bit) SQL Anywhere where I copied the dbcapi.dll on the 64-bit test machine. My path was already set.
To summarize - when running ruby 1.9.3p385 (2013-02-06) [i386-mingw32] to use the sqlanywhere gem (sqlanywhere-0.1.6-x86-mingw32) ensure the following:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Assuming the following gems are installed properly,
Connection via dbd-sqlanywhere
DBI.connect('DBI:ODBC:Agency') seems to be wrong.
It should use SQLAnywhere instead of ODBC. for example,
DBI.connect('DBI:SQLAnywhere:Agency')
where Agency is the server name.
http://dcx.sybase.com/index.html#1201/en/dbprogramming/pg-ruby-dbi.html might help.
Connection via sqlanywhere
Not sure exactly what you try to do, the provided script/result does not seem to match.
The script below should work regardless of connection.
require 'sqlanywhere'
api = SQLAnywhere::SQLAnywhereInterface.new()
SQLAnywhere::API.sqlany_initialize_interface( api )
api.sqlany_init()
The provided call stacks seems to show that you try to run sqlanywhere_test.rb. But sqlanywhere_test.rb expects the database test.db running, which I guess you haven't done.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It should be noted that DBI.connect('DBI:ODBC:Agency') is valid, however, you are instrucing Ruby/DBI to use the DBI::ODBC library (http://ruby-dbi.rubyforge.org/rdoc/). If this case, the SQL Anywhere Ruby library is not being used at all. Instead, the DBI::ODBC driver will be directly interfaceing with the SQL Anywhere ODBC driver.
By comparison, using the SQL Anywhere driver with DBI.connect('DBI:SQLAnywhere:Agency') does not go through ODBC. Instead it interfaces directly with the lower-level SQL Anywhere libraries.
As a result, the two failure mentioned in the question (dbi and sqlanywere) are actually different failures, because the first one is using the ODBC library, and the second one is using the sqlanywhere library.
However, the root cause may be similar. Similar to the other answer to this question, since Ruby is 32-bit, you should check to make sure you have the 32-bit ODBC driver installed. Also, you must set up the DSN using the 32-bit ODBC Manager (C:\\WINDOWS\\SysWOW64\\odbcad32.exe), not the 64-bit one.
A few additional questions:
As a sample, here is my output:
C:\\>irb irb(main😞001:0> require 'sqlanywhere' => true irb(main😞002:0> api = SQLAnywhere::SQLAnywhereInterface.new() => #<SQLAnywhere::SQLAnywhereInterface:0x2d02220> irb(main😞003:0> SQLAnywhere::API.sqlany_initialize_interface( api ) => 1 irb(main😞004:0> api.sqlany_init() => [1, 2]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Eric for responding.
Here is the sample script using IRB
irb(main):001:0> require 'sqlanywhere' => true
irb(main):002:0> api = SQLAnywhere::SQLAnywhereInterface.new() => #<sqlanywhere::sqlanywhereinterface:0x22aa330>
irb(main):003:0> SQLAnywhere::API.sqlany_initialize_interface( api ) => 0
irb(main):004:0> api.sqlany_init()
It is at this point the IRB window crashes. If I run the same code through the Scite Editor, I am able to provide the output in original query.
It would appear that you are running 32-bit Ruby (you can check this with Ruby -v). The SQL Anywhere Ruby library needs to interface with SQL Anywhere DB C API library (dbcapi.dll). Can you check if you have the 32-bit SQL Anywhere library installed? It would likely be in C:\\Program Files\\SQL Anywhere 12\\Bin32\\dbcapi.dll.
If it is there, check to make that C:\\Program Files\\SQL Anywhere 12\\Bin32 is in your path.
User | Count |
---|---|
73 | |
10 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.