Jul 022011

Hi All,

I have just worked up a short script to search a SQL server using Javascript.
Using ActiveX and the ADoDB.Connection object this enables me to build a little HTA frontend to do what I need.

Firstly, we create the ADODB object.

var objConnection = new ActiveXObject("adodb.connection");

Then, set the options we want for the connection.
I’m connecting to a SQL server, that is hosted on “server1”, and the database i want is “db1”, and I’m connecting with username and passwords.

var strConn = "driver={sql server};server=server1;database=db1;uid=username;password=password";

Then we open the connection with the options specified.


Once the connection has been opened, we use the ADODB.Recordset object to execute a query and retrieve results from SQL.

var rs = new ActiveXObject("ADODB.Recordset");
var strQuery = "SELECT * FROM users WHERE username = 'user1'";

Once the query has been executed, the results will be stored in the recordset.
You will now be able to view the results using the standard recordset functions.

while(!rs.eof) {
//Do your thing here