Node.js Tutorial
Below is sample node.js program which will connect node.js application with MSSQL server.
//Create a JavaScript file index.js or app.js
var webconfig = {
user: 'login',
password: 'sa@123',
server: 'localhost',
database: 'TestDB',
options: {
encrypt: false // Use this if you're on Windows Azure
}
}
var express = require('express');
var sql = require('mssql');
var http = require('http');
var app = express();
var port = process.env.PORT || 8000;
var connection = new sql.Connection(webconfig, function(err) {
var request = new sql.Request(connection);
request.query('select * from Users', function(err, recordset) {
if(err) // ... error checks
console.log('Database connection error');
console.dir("User Data: "+recordset);
});
});
app.listen(port);
console.log(port+' is the magic port');
Hi, i tried the code but i had an error : sql.Connection is not a constructor
ReplyDeletechange Connection to ConnectionPool
DeleteEverything is fine .still showing
ReplyDelete8000 is the magic port
Database connection error
'User Data: undefined'
var express = require('express');
ReplyDeletevar sql = require('mssql');
//var http = require('http');
var app = express();
var webconfig = {
host: 'localhost',
user: 'test123',
password: 'rinku',
database: 'node_db'
// options: {
// encrypt: false // Use this if you're on Windows Azure
// }
}
var port = process.env.PORT || 8000;
var connection = new sql.connect(webconfig, function (err) {
debugger
var request = new sql.Request(connection);
request.query('select * from tblstudent', function (err, recordset) {
if (err) // ... error checks
console.log('Database connection error');
console.dir("User Data: " + recordset);
});
});
app.listen(port);
console.log(port + ' is the magic port');
this is my code
ReplyDelete