Reputation: 6246
I am trying to run the simplest hello world with Node.js and the mssql
package.
https://www.npmjs.org/package/mssql
mssql
package page to the js file.npm install mssql
which is successful.What happens is that the code doesn't get into the callback after creating a connection. So in the code below:
var connection = new sql.Connection(config, function(err) {
alert(1);
...
//more code...
});
I never get to the alert. No exceptions or errors either
I am probably missing something... Can you please help me spot it?
Update: I should mention that the DB is on Azure...
Upvotes: 0
Views: 1485
Reputation: 6246
OK, after digging a bit in the docs for Tedious, I found out that if the DB is on Azure you must include options: {encrypt: true}
in your configuration object.
Now everything is working as expected.
Upvotes: 1
Reputation: 20014
Try this on your server side it works fine on my end:
var sql = require("mssql");
var dbConfig = {
user:'sa',
password:'password1',
server:'serverName',
database:'DBName'
};
var connection = new sql.Connection(dbConfig, function (err) {
console.log(err);
var request = new sql.Request(connection);
request.query("Select 'Hello World' as var1", function (err, recordset, returnValue) {
if (!err ){
console.log(recordset) ;
}else{
console.log(err)
}
});
});
Upvotes: 1