TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Connect Node JS with SQL Server
Ananth Ananthakrishnan
Nov 14
2014
Code
1.6
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
var sql = require(
'msnodesql'
);
var util = require(
'util'
);
var connStr =
"Driver={SQL Server Native Client 11.0};Server=servername;Database=Test;UID=sa;PWD=pwd"
;
var query =
"SELECT * FROM Country"
;
// Load the http module to create an http server.
var http = require(
'http'
);
console.log(connStr);
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
sql.query(connStr,
"SELECT * from Country"
, function (err, results) {
for
(var i = 0; i < results.length; i++) {
console.log(
"CId: "
+ results[i].CId +
" Cname: "
+ results[i].Cname);
}
});
});
server.listen(8000);
console.log(
"Server running at http://127.0.0.1:8000/"
);
NodeJS
SQL Server