1

I need to connect to SQL Server using nodeJs. This is the connection string normally I used for .NET

Data Source=DESKTOP-QPC8N68\SQLEXPRESS;Initial Catalog=ProjectX;Integrated Security=True

I'm using the mssql npm package and my code as follows:

app.get('/', function (req, res) {
    var sql = require("mssql");

    var config = {
        server: 'localhost\\SQLEXPRESS',
        database: 'ProjectX',

        options: {
            trustedConnection: true
        }
    };

    sql.connect(config).then(function (ar) {
        console.log('connected');
        console.log(ar);
    }).catch(function (ex) {
        console.log(ex);
    });

    res.send('OK');
});

I'm getting the following error

ConnectionError: Failed to connect to localhost:undefined in 15000ms
at Connection. (C:\Drive F\NodeSql\node_modules\mssql\lib\tedious.js:378:25)
name: 'ConnectionError',
message: 'Failed to connect to localhost:undefined in 15000ms',
code: 'ETIMEOUT'

ConnectionError: Failed to connect to localhost:undefined in 15000ms
at Connection.
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5) at Timer.listOnTimeout (timers.js:207:5)
name: 'ConnectionError',
message: 'Failed to connect to localhost:undefined in 15000ms',
code: 'ETIMEOUT'

I'm using Windows authentication to connect to SQL Server. What is missing here and what npm package do you recommend to connect to SQL Server?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nuwan.Niroshana
  • 407
  • 4
  • 15
  • Can someone help on this ? – Nuwan.Niroshana Dec 19 '16 at 02:01
  • Possible duplicate of [How to connect to SQL Server with windows authentication from Node.JS using mssql module](https://stackoverflow.com/questions/33709807/how-to-connect-to-sql-server-with-windows-authentication-from-node-js-using-mssq) – getglad Mar 05 '18 at 18:53

0 Answers0