我想将雪花数据库连接到我的Rails红宝石应用程序。因此,我创建了一个试用帐户,并在雪花中创建了一个演示数据库。
现在,我正在尝试将其与我的应用程序集成。但是我无法连接雪花数据库。
我关注了以下链接,
**
**
#!/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。
能否请您帮我解决这个问题。