如何解决雪花Ruby连接器
我想将雪花数据库连接到我的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。
能否请您帮我解决这个问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。