-
-
Save burningTyger/3c021e0f212e8f85e7d73bea55341011 to your computer and use it in GitHub Desktop.
Sequel: Connecting to Microsoft Access(*.accdb)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tested Environment | |
# Windows7 x64, MS Access2010/2013, sequel 4.11.0 | |
# Gemfile | |
# source 'https://rubygems.org' | |
# gem 'sequel' | |
# gem 'ruby-odbc' # for ODBC | |
require 'sequel' | |
ACCDB_PATH = '//127.0.0.1/db/Sample.accdb' | |
OLEDB_PROVIDER = 'Microsoft.ACE.OLEDB.12.0' | |
ODBC_DRIVER = '{Microsoft Access Driver (*.mdb, *.accdb)}' | |
DSN = 'SequelTest' | |
def test(db, name) | |
db.test_connection | |
p "#{name}: OK" | |
rescue Sequel::DatabaseConnectionError | |
p "#{name}: ERROR" | |
end | |
# Using ADO (Unuse gem 'ruby-odbc') | |
db1 = Sequel.ado(conn_string: "Provider=#{OLEDB_PROVIDER};Data Source=#{ACCDB_PATH}") | |
test(db1, 'ADO') | |
# Using ODBC(Need gem 'ruby-odbc') | |
# DSN | |
db2 = Sequel.odbc(DSN) | |
test(db2, 'DSN') | |
# DSN Less | |
db3 = Sequel.odbc(drvconnect: "Driver=#{ODBC_DRIVER};Dbq=#{ACCDB_PATH};") | |
test(db3, 'DSN Less') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment