Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

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'



        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::API.sqlany_initialize_interface( api ) 


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] 
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:

    1 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/ 
    2 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/ 
    3 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/ 
    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/ 
   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/ 
   31 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/ 
   32 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/ 
   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/

You may have encountered a bug in the Ruby interpreter or extension libraries. 
Bug reports are welcome. 
For details:

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

asked 03 Apr '13, 20:29

Kevin%20Scott's gravatar image

Kevin Scott
accept rate: 0%

edited 03 Apr '13, 20:30

Assuming the following gems are installed properly,

  • gem install sqlanywhere
  • gem install dbi
  • gem install dbd-sqlanywhere

  1. Connection via dbd-sqlanywhere

    DBI.connect('DBI:ODBC:Agency') seems to be wrong.

    It should use SQLAnywhere instead of ODBC. for example,


    where Agency is the server name. might help.

  2. 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::API.sqlany_initialize_interface( api )


    • 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.

permanent link

answered 04 Apr '13, 10:40

Jason%20Kim's gravatar image

Jason Kim
accept rate: 0%

edited 04 Apr '13, 10:42

It should be noted that DBI.connect('DBI:ODBC:Agency') is valid, however, you are instrucing Ruby/DBI to use the DBI::ODBC library ( 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.

(04 Apr '13, 11:39) Eric Farrar

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:

  1. dbcapi.dll exists in the following folder structure - C:\Program Files\SQL Anywhere 12\Bin32
  2. Make sure your path includes C:\Program Files\SQL Anywhere 12\Bin32
permanent link

answered 04 Apr '13, 12:23

Kevin%20Scott's gravatar image

Kevin Scott
accept rate: 0%

edited 04 Apr '13, 12:59

Mark%20Culp's gravatar image

Mark Culp

A few additional questions:

  1. What version of SQL Anywhere are you running?
  2. Did you install the pre-built binary version of the gem (aka. gem install sqlanywhere), or build it yourself from source?
  3. Could you please run your sample script in IRB and post the output?

As a sample, here is my output:

irb(main):001:0> require 'sqlanywhere'
=> true
irb(main):002:0> api =
=> #<SQLAnywhere::SQLAnywhereInterface:0x2d02220>
irb(main):003:0> SQLAnywhere::API.sqlany_initialize_interface( api )
=> 1
irb(main):004:0> api.sqlany_init()
=> [1, 2]
permanent link

answered 04 Apr '13, 10:14

Eric%20Farrar's gravatar image

Eric Farrar
accept rate: 30%

edited 04 Apr '13, 10:28

Thanks Eric for responding.

  1. The version of SQL Anywhwere is
  2. I installed via the gem. I did not build from source.
  3. Here is the sample script using IRB

    irb(main):001:0> require 'sqlanywhere' => true

    irb(main):002:0> api = => #<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.

(04 Apr '13, 10:29) Kevin Scott

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.

(04 Apr '13, 11:18) Eric Farrar

irb(main):003:0> SQLAnywhere::API.sqlany_initialize_interface( api ) => 0 means DBCAPI sqlany_initialize_interface failed. Can you check dbcapi.dll exists and PATH variable points to the directory?

(04 Apr '13, 11:23) Jason Kim
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 03 Apr '13, 20:29

question was seen: 3,087 times

last updated: 04 Apr '13, 12:59