简体   繁体   中英

Connecting Sql Server though Node.js

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?

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 + ")");

    });
});    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM