Reputation: 4942
Has anyone had any success getting Node to communicate with a SQL Server database?
I've tried all the solutions posted on Stackoverflow (although all relevant questions seem to be about a year old) and none of them have worked.
Some of the packages I've tried:
and some others that I can't remember their names
I think all the packages are out of date or not being maintained anymore, as far as I can see there is no defacto standard. I'm starting to think I should abandon trying to use a SQL Server database and switch to MySQL instead?
I'm developing in Visual Studio 2012 and I also have SQL Server 2012.
Upvotes: 0
Views: 1372
Reputation: 1049
this setting work in express.js 2022, sql server 2014
var sql = require('mssql');
var config = {
user: 'your user',
password: 'your password',
server: 'your server',
database: 'your database',
"options": {
"encrypt": false,
"enableArithAbort": true,
"trustServerCertificate":false
}
};
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from a_pinfinger', function (err, recordset) {
if (err) console.log(err)
// send records as a response
//res.send(recordset);
console.log(recordset);
});
});
Upvotes: 0
Reputation: 1048
I'am author of node-mssql module and i would like to help you solve your problem. Could you please provide more information about the errors you get and config you're using? I have made some changes in connection errors recently, so maybe you could try latest version 0.5.0.
Also you could try precompiled msnodesql drivers here. I was also unable to install it on my machine via npm. If this will work for you, try using node-mssql with msnodesql as an optional driver, it can save you a lot of lines of code and make you work with SQL Server more enjoyable.
Upvotes: 2