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.

Patrik Šimek
  • 1,038
  • 10
  • 14
Ally
  • 4,894
  • 8
  • 37
  • 45
  • Have you tried: https://github.com/WindowsAzure/node-sqlserver – WiredPrairie Jan 16 '14 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. – Ally Jan 16 '14 at 18:11

2 Answers2

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.

Patrik Šimek
  • 1,038
  • 10
  • 14
  • 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? – Ally Mar 07 '14 at 16:30
  • Yes, sure, Iam here to help. – Patrik Šimek Mar 07 '14 at 17:31
  • 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}}` – Ally May 28 '14 at 13:07
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);
});
});
reza rahmad
  • 1,009
  • 10
  • 16