1

I want to connect to SqlServer through Node.js.

I have tried many ways and many links but nothing is work properly. I want to connect to SqlServer and fetch some data.

Please can someone suggest some steps and code to connect SqlServer 2008. What is the Driver for Sql-Node.js?

Jimbo
  • 25,790
  • 15
  • 86
  • 131
HomeWork
  • 263
  • 1
  • 4
  • 14

1 Answers1

1

I just did it following this walkthrough at http://tech.pro/tutorial/1848/getting-nodejs--sql-server--azure-to-work-together

He's using the "msnodesql" package at https://www.npmjs.org/package/msnodesql, code at git-hub at https://github.com/WindowsAzure/node-sqlserver, and I've got it running in a node-console app with a simple select-statement:

var mssql = require('msnodesql');

var conn_str = "Driver={SQL Server Native Client 10.0};Server=tcp:xxxxx;Database=yyyy;Uid=zzzz;Pwd=wwww;Connection Timeout=30;";

    mssql.query(conn_str, "select * from testtable", function(err, recordset) {
    if(err){
        console.log("Got error :-( " + err);
        return;
    }

    recordset.forEach(function(record) {
        console.log("name: " + record.Name + " (" + record.ID + ")");

    });
});    
Johan Danforth
  • 4,469
  • 6
  • 37
  • 36