Today i am going to write how to connect a NodeJS Application to a MSSql database.
To connect to the sql server you have to do this:
1-) First download this library:
npm install --save mssql
2-) The second step is to connect to the database:
var sql = require('mssql');
var config = {
user: "dbuser",
password: "dbpassword",
server:"dbservername",
database: "dbname"
//use this on windows azure
//options {
// encrypt: true;
//}
};
sql.connect(config, function (err) {
console.log(err);
});
3-)Then to got the data you just need to write this:
var request = new sql.Request();
request.query('select * from Customer', function (err, recordset) {
console.log(recordset);
})
As you can see is very simple connect a nodejs application to mssql.
No hay comentarios:
Publicar un comentario