Connecting to a MS Access Database using JavaScript

Posted on 20 Dec 2007, 5:23pm, in , , . 1 comment

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.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

If you do not have ASP then I can see a use for this.

*name

*e-mail

web site

leave a comment


Latest Tweet

twitter icon

starting to get thoroughly fucked off!

Subscribe

Subscribe to my various RSS feeds from the blog and other websites