雪花Ruby连接器

问题描述

我想将雪花数据库连接到我的Rails红宝石应用程序。因此,我创建了一个试用帐户,并在雪花中创建了一个演示数据库

现在,我正在尝试将其与我的应用程序集成。但是我无法连接雪花数据库

我关注了以下链接

https://community.snowflake.com/s/article/connecting-to-snowflake-using-the-obdc-driver--ruby-on-rails-5

**

**

#!/usr/local/bin/ruby 
# odbc-sNowflake.rb - access database via ODBC using Sequel gem 
require 'odbc' # gem 'ruby-odbc' 
require 'sequel' # gem 'sequel'
begin 
db = Sequel.odbc('<sNowflake dns>',user: '<username>',password: '<password>') 
puts 'SELECT * FROM sales LIMIT 10' 
db.fetch('SELECT * FROM sales LIMIT 10') do |row| 
puts row 
end 
rescue => e 
puts 'An error occurred' 
puts "Error code: #{e.inspect}" 
ensure 
# disconnect from server 
db.disconnect if db 
end

odbc.ini文件中的DNS条目在哪里。

我的odbc.ini

[DEMODNS]
Driver        = /usr/local/lib/libodbcinst.so
Locale        = en-US;
Server        = zxa09427.us-east-1.sNowflakecomputing.com;
Port        = 443;
Account       = zxa09427.us-east-1;
Database      = DEMO_DB;
Schema        = PUBLIC;
Warehouse     = COmpuTE_WH;
Role          = SYSADMIN;
SSL           = on;
Query_Timeout = 270;
uid           = kingston;
pwd           = *******

我遇到以下错误

[kingston.jenorish@kingston工作] $ ruby​​ sequel_demo.rb

An error occurred
Error code: #<Sequel::DatabaseConnectionError: ODBC::Error: IM004 (0) [unixODBC][Driver Manager]Driver's sqlAllocHandle on sql_HANDLE_HENV Failed>

所以我尝试了另一个链接

https://www.cdata.com/kb/tech/snowflake-odbc-ruby.rst

代码

#connect to the DSN
require 'dbi'
cnxn = DBI.connect('DBI:ODBC:DEMODNS','kingston','*****')

#execute a SELECT query and store the result set
resultSet = cnxn.execute("SELECT Id,ProductName FROM Products")

#display the names of the columns
resultSet.column_names.each do |name|
  print name,"\t"
end
puts

#display the results
while row = resultSet.fetch do
  (0..resultSet.column_names.size - 1).each do |n|
    print row[n],"\t"
  end
  puts
end
resultSet.finish

#close the connection
cnxn.disconnect if cnxn

错误

[kingston.jenorish@kingston工作] $红宝石SNowflakeSelect.rb

/home/user/.rvm/gems/ruby-2.0.0-p648/gems/dbd-odbc-0.2.5/lib/dbd/odbc/driver.rb:36:in rescue in connect: IM004 (0) [unixODBC][Driver Manager]Drivers sqlAllocHandle on sql_HANDLE_HENV Failed (DBI::DatabaseError)

当我尝试连接isql时,

[kingston.jenorish@kingston Work]$ isql -v DEMODNS


[IM004][unixODBC][Driver Manager]Drivers sqlAllocHandle on sql_HANDLE_HENV Failed
[Isql]ERROR: Could not sqlConnect

我在Linux centos上使用ruby 2。

能否请您帮我解决这个问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)