Connecting to a MS Access Database using JavaScript

December 20th, 2007

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.

Development | Comments | Trackback

One Response to “Connecting to a MS Access Database using JavaScript”

  1. 1Access Developer
    March 8th, 2010 @ 9:53 am

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

Leave a Reply

  1.  
  2.  
  3.  
  4. XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
You can keep track of new comments to this post with the comments feed.

Search

About Me

Web Developer with amazingness knowledge of ExtJS, jQuery, PHP, ASP, SQL. Keen follower of F1 & Football and all things tech.

Now Playing

No, It Isn't by +44
from the album When Your Heart Stops Beating.
0 days ago via last.fm.

Recent Posts

Recent Comments

Categories

So Meta