2012-04-19 5 views
0

MS SQLデータベースに接続するためにSequelを取得する際に問題が発生しています。MacでのODBC Ruby Sequelのライオン

  • unixODBCの
  • FreeTDSの

私は両方のソフトウェア・パッケージを構成しているし、次のコマンドは、私は問題なく私のデータベースに接続することができます::

    私は次のようにインストールされている
  • isql
  • tsql
  • osqlを

しかし、私はSequel.odbcコマンドを使用して、Rubyコードからそれをしようとしたとき、私は、次のエラーが表示さ:

ODBC ::エラー:IM003(0)[iODBCを] [Driver Managerを]指定されたドライバをロードできませんでした。

これは私が得る限りです。私は最初に別のエラーを受け取りましたが、構成部分をやり直すことでそれを解決することができました。私はそこに何かを逃したと思う。

EDIT

これは私のベースの話者クラスのコードです。基本的には、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 

ban/unban関数のいずれかを呼び出すと、エラーメッセージが表示されます。

EDIT2

私は、フォルダ/ライブラリ/ ODBCを追加し、iODBCのためにそこにすべての設定ファイルをリンクしました。これは私が前に持っていたエラーを削除し、今私は、このエラーをもたらします:

ODBC ::エラー:01000(20002)[FreeTDSの] [SQL Serverの] Adaptive Serverの接続が

を失敗だから、私はいくつかを作ったようです進歩する

+0

あなたのコードを表示する必要があります。これは可能な限り簡単なテストケースですが、失敗する可能性があります。 – Phrogz

+0

は要求されたソースコードを追加しました。 –

答えて

0

OS XからMicrosoft SQL Serverに接続する場合は、odbcアダプタの代わりにtinytdsアダプタを使用することをお勧めします。Sequel/ODBCをWindows以外のボックスで実行している人がいますが、 Windows上のSequel/ODBCの経験があるだけです。

関連する問題