Connecting to a MS Access Database using JavaScript
I have been searching for a technique to connect to a MS Access database solely using JavaScript for some time now. Until recently I have been totally out of luck.
Before I go on and reveal the method behind the madness let me make a few things crystal clear!
This is 100% advised against for anything other than in-house work e.g. Intranets as it is not a secure method.
So anyway here’s the code to achieve it. (line wraps marked »)
var conn = new ActiveXObject("ADODB.Connection");
var rs = new ActiveXObject("ADODB.Recordset");
conn.ConnectionTimeout = 15;
conn.CommandTimeout = 15;
var connStrng = "Provider=Microsoft.Jet.OLEDB.4.0; »
Data Source=database.mdb; »
Persist Security Info=False"; // remember to escape \ if needed.
conn.open(connStrng);
rs.open("SQL Statement", conn);
var fields=new Array();
var i=0; while(!rs.eof) {
var = fields[i]=rs.fields("Field Name").value;
i++; rs.moveNext();
};
rs.close();
conn.close();
Hope it helps.