0

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:

  • msnodesql (Unable to get it to install successfully),
  • mssql, tedious (Always errors out on socket connection)

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.

2
  • Have you tried: github.com/WindowsAzure/node-sqlserver Commented Jan 16, 2014 at 18:04
  • @WiredPrairie I'm afraid I have. I hit multiple errors when trying to build it, it complains about something relating to Visual Studio 2010 (I have 2012). Currently installing something Visual Studio 2010 related as a long shot to getting it to build, but I doubt it will work. Seems to me it's just very out of date. Commented Jan 16, 2014 at 18:11

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry for not getting back to you on this, I meant to then got side tracked then forgot. I decided to move away from MSSQL and node after not being able to get it working. But I will revisit it if you'd still like to work on a fix?
Yes, sure, Iam here to help.
I figured it out, in my config I must specify the port and not the instance name. Thanks for your help. e.g. var config = {user:'****',password:'****',server:'localhost',database:'MyDatabase', options:{port:1433}}
0

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);
});
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.