Accessing .mdb files through nodejs [closed]
Asked Answered
A

4

35

I want to Access .mdb files and manipulate like insert / update using nodejs

Please suggest a library that would suite the need.

Thanks.

Ardithardme answered 29/1, 2014 at 9:29 Comment(1)
Is node's default file system library (nodejs.org/api/fs.html) insufficient for your needs?Ebberta
F
30

Slightly different but node-adodb worked well for me for .accdb files:

https://www.npmjs.org/package/node-adodb

// Get the adodb module
var ADODB = require('node-adodb');
ADODB.debug = true;

// Connect to the MS Access DB
var connection = ADODB.open('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\dbs\\my-access-db.accdb;Persist Security Info=False;');

// Query the DB
connection
    .query('SELECT * FROM [TestTable];')
    .on('done', function (data){
        console.log('Result:'.green.bold, data);
    })
Fortyfour answered 7/10, 2014 at 10:4 Comment(3)
This only works if you are running Windows. It throws errors on a mac or linux OS because it requires MSAccess Drivers. If you do not have Access installed on your Win OS you can install just the driver here for 2010 microsoft.com/en-us/download/details.aspx?id=13255Guthrie
It's written in pure javascript. No node-gyp needed like node-odbc. Works perfectly!Schwarz
It's nice when the question is answered and not criticised. There are numerous reasons to want to do this AND have no choice over replacing a JET database. This answer provides the solution to many database questions. I'm curious how it could be pure Javascript though. If it's true, then quite impressive accessing the ADO COM.Durden
H
8

This article describes the process for connecting PHP to an Access .mdb database: http://www.sitepoint.com/using-an-access-database-with-php/

The process for Node.js is quite similar - it's just another ODBC data source.

You'll need a node ODBC package, such as: https://github.com/wankdanker/node-odbc

https://github.com/markdirish/node-odbc/

Then you'll need to format your ODBC connection string. eg.

"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=MyDatabase; Uid=; Pwd=;"
Halfassed answered 29/1, 2014 at 13:34 Comment(4)
Will it work like path = "/path/to/the/file.mdb"; "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="+path+"; Uid=; Pwd=;"Ardithardme
It seems Dbq does support a path.Halfassed
Also, if you are using this driver with a 64-bit application (eg Node.js 64-bit) to access an .mdb or .accdb file directly, you may have issues. If you do, the following may be relevant: MS Office usually installs Microsoft Access Driver 32-bit which is incompatible with 64-bit apps. You'll need to 1) uninstall MS Office 2) download & install the Microsoft Access Database Engine 2010 Redistributable (x64) at microsoft.com/en-us/download/details.aspx?id=13255 3) install MS Office againNewtonnext
That sounds rather inconvenientHalfassed
R
4

My suggestion is OWIN module which is currently developed as Edge.js by Mr Tomasz Janczuk.

Recognizor answered 23/4, 2014 at 13:21 Comment(0)
B
0

Well i had this same issues too, the code below was able to fix mine

const path = require('path');
const ADODB = require('node-adodb');


const connectionString = path.resolve(__dirname, './test1.mdb');
const connection = ADODB.open(`Provider=Microsoft.Jet.OLEDB.4.0;Data Source=${connectionString};`);

connection.query("SELECT * FROM users").then((data) => {
    console.log(data);
}).catch(err => {
    console.error(JSON.stringify(err))
});
Bolshevik answered 30/4 at 19:36 Comment(2)
Use the code above to fix itBolshevik
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Fructuous

© 2022 - 2024 — McMap. All rights reserved.