本文介绍了带有Ruby连接字符串的ODBC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Ruby访问Access数据库。

I'm trying to access an Access database from Ruby.

dbh = DBI.connect('DBI:ODBC:test','','')

有效,但是

 dbh = DBI.connect("DBI:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=H:/test.accdb")

不。

我不想要在每台单机上设置访问驱动程序。

I don't want to setup the Access Driver on every single machine.

为什么第二行不起作用?

Why isn't the second line working?

ODBC驱动程序说我的程序无法识别类似数据库的内容。

The ODBC-driver says something like the database wasn't recognized by my program.

推荐答案

我从未使用过新的 accdb 格式,但我通过和续集。

I never worked with the new accdb-format, but I connected successful to mdb-files via the Jet-engine and sequel..

如果它与accdb文件一起使用,您可以测试我的代码示例:

You may test my code example if it works with your accdb-file:

require 'sequel'

Dir['*.mdb'].each{|mdb|
      print "Check #{mdb}"
      @db = Sequel.ado(:conn_string=>"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=#{mdb}")
      begin
        @db.test_connection
        puts " ok"
      rescue Sequel::DatabaseConnectionError
        puts " error"
      end
}

如果您希望使用Winole-variant,可以检查

If you prefer a winole-variant you may check How do I query a MS Access database table, and export the information to Excel using Ruby and win32ole?

这篇关于带有Ruby连接字符串的ODBC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:57
查看更多