我遇到了Sequel连接到MS SQL数据库的问题。 我安装了以下内容:
我已经配置了两个软件包,以下命令允许我连接到我的数据库而没有问题:
但是,当我使用Sequel.odbc命令从Ruby代码尝试它时,我收到以下错误:
ODBC ::错误:IM003(0)[iODBC] [驱动程序管理器]无法加载指定的驱动程序。
这是我能得到的。我曾经先收到另一个错误,但设法通过重做配置部分来解决这个问题。猜猜我错过了什么。
修改
这是我的基础讲话者课程的代码。它基本上像rails一样加载一个YAML文件,保存数据库设置并建立与数据库的连接。 这似乎有效,尝试手动从续集中返回一个DB对象:
module Talkers
require 'yaml'
require 'sequel'
class BaseTalker
# This function will load the desired settings as a hash from the database.yml file
# in the config folder. The data will be returned as a hash following the standard
# YAML structure.
def self.load_config(name)
cfg = YAML::load(File.open(File.join(ENV['API_ROOT'], 'config', 'database.yml')))
cfg.key?(name) ? cfg[name] : nil
end
# This function will establish a connection with the Florensia User database and return
# the Sequel database object, so that queries can be executed against the database.
def self.connect_to_user_db
settings = self.load_config("florensia_user_#{ENV['RACK_ENV']}")
Sequel.odbc settings['dsn'], :db_type => settings['adapter'], :user => settings['user'], :password => settings['password']
end
end
end
下面的类继承自讲话者并为用户执行某些操作。它包含特定于游戏的DB逻辑。当我调用这个逻辑时,我收到错误:
module Talkers
require 'yaml'
require 'sequel'
class LoginDbTalker < BaseTalker
#
# Bans the specified User from the game. The function requires the following information
# to be supplied in order for the ban to be properly set:
# - id : The identifier of the account.
# - gm_name : The name of the GM setting the ban.
# - punish_code : The punishment code being applied on the account.
# - days : The duration of the ban in days, starting from today.
#
# The function will return true if the ban has been properly set; otherwise the function
# will return false.
def self.ban_user(options = {})
return false if options.empty?
db = self.connect_to_user_db
ds = db[:tbl_User].filter(:id => options[:id])
ps = ds.prepare(:update, :apply_ban)
ps.call(
:punishcode => options[:punish_code],
:punishstory => "Banned by #{options[:gm_name]}",
:punishdate => Date.today,
:punishfreedate => (options[:days].to_i == -1) ? (Date.today + (30 * 265)) : (Date.today + options[:days].to_i))
true
rescue Exception => e
puts "Exception caught in ban_user: #{e.to_s}"
puts "Provided variables: id=#{options[:id]}, gm_name=#{options[:gm_name]}, punish_code=#{options[:punish_code]}, days=#{options[:days]}"
false
end
#
# Unbans the specified User from the game. The function requires the following information
# to be supplied in order for the ban to be properly lifted:
# - id : The identifier of the account.
# - gm_name : The name of the GM removing the ban.
#
# The function will return true if the ban has been properly lifted; otherwise the function
# will return false.
def self.unban_user(options = {})
db = self.connect_to_user_db
ds = db[:tbl_User].filter(:id => options[:id])
ps = ds.prepare(:update, :lift_ban)
ps.call(
:punishcode => '0',
:punishstory => "Ban removed by #{options[:gm_name]}",
:punishdate => Date.today,
:punishfreedate => Date.today
)
true
rescue Exception => e
puts "Exception caught in unban_user: #{e.to_s}"
puts "Provided variables: id=#{options[:id]}, gm_name=#{options[:gm_name]}"
false
end
#
# Kicks the specified User from the game, regardless on the server or character he currently is on.
# This requires a direct connection to the game servers so a specialized command can be sent that
# instruct the server to close the connection with the offending player.
# The function returns true if the kick succeeded; otherwise false.
def self.kick_player(id)
false
end
end
end
调用任何禁止/取消功能会导致错误消息。
EDIT2
我添加了文件夹/ Library / ODBC,并将所有配置文件链接到iODBC。这消除了我以前的错误,现在给我带来了这个错误:
ODBC ::错误:01000(20002)[FreeTDS] [SQL Server] Adaptive Server连接失败
所以我似乎再次取得了一些进展
答案 0 :(得分:0)
如果您从OS X连接到Microsoft SQL Server,我建议您使用tinytds适配器而不是odbc适配器。我知道有些人在非Windows机器上运行Sequel / ODBC,但我只有经验在Windows上使用Sequel / ODBC。