Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby and accdb (ms access)

If I have a base windows xp system, ruby and an ms access 2007 file (say c:/foo/bar.accdb) file, what's the least intrusive method for reading that .accdb file.

  • What needs to be installed on the xp system.
  • What is the specific connection string.
like image 257
David Nehme Avatar asked Jul 13 '09 15:07

David Nehme


People also ask

What is Accdb in Access?

A file with . accdb extension is a Microsoft Access 2007 database file that stores users data in tables. It supports storing custom forms, SQL queries, and other data.

Is Accdb better than MDB?

ACCDB provides better integration with SharePoint and Outlook when compared to MDB. Unlike MDB, ACCDB allows the use of multi-valued fields, making it easier to store multiple choices in the same field. ACCDB provides improved encryption of database contents compared to MDB.

What programs can open Accdb?

ACCDB files can be opened with Microsoft Access (version 2007 and newer). Microsoft Excel will import ACCDB files but that data will then have to be saved in some other spreadsheet format. The free MDB Viewer Plus program can also open and edit ACCDB files.


1 Answers

Something along these lines should get you started. Of course, you'll need to modify some of the values like; path, filename, SQLstatement, etc.

MDB file (Access 2003 format and older) using the Jet engine

require 'win32ole'
connection = WIN32OLE.new('ADODB.Connection')
connection.Open('Provider=Microsoft.Jet.OLEDB.4.0;
                 Data Source=c:\path\filename.mdb')

ACCDB file (Access 2007 format and newer) using the ACE engine

require 'win32ole'
connection = WIN32OLE.new('ADODB.Connection')
connection.Open('Provider=Microsoft.ACE.OLEDB.12.0;
                 Data Source=c:\path\filename.accdb')

To execute a SQL query that doesn't return data use:

connection.Execute("INSERT INTO Table VALUES ('Data1', 'Data2');")

To perform a query that returns a recordset:

recordset = WIN32OLE.new('ADODB.Recordset')
recordset.Open(SQLstatement, connection)
like image 100
KevenDenen Avatar answered Oct 18 '22 04:10

KevenDenen