0
votes

I am currently trying to establish a connection to a SQL Server instance on my local machine with the following Node program, app.js:

var sql = require('mssql');

sql.connect("mssql://sa:temp2@localhost/Northwind").then(function() {
    // Query 

    new sql.Request().query('select * from TableName').then(function(recordset) {
        console.dir(recordset);
    }).catch(function(err) {
        console.log(err);
    });

}).catch(function(err) {
    console.log(err);
});

And the error:

{ ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED 127.0.0.1:1433

at Connection. (C:\Users\name\nodeprac\node_modules\mssql\lib\tedious.js:378:25)

at Connection.g (events.js:286:16)

at emitOne (events.js:96:13)

at Connection.emit (events.js:188:7)

at Connection.socketError (C:\Users\name\nodeprac\node_modules\tedious\lib\connection.js:531:14)

at emitOne (events.js:96:13)

at Socket.emit (events.js:188:7)

at emitErrorNT (net.js:1272:8)

at _combinedTickCallback (internal/process/next_tick.js:74:11)

at process._tickCallback (internal/process/next_tick.js:98:9)

name: 'ConnectionError',

message: 'Failed to connect to localhost:1433 - connect ECONNREFUSED 127.0.0.1:1433',

code: 'ESOCKET' }

I've tried a million other ways of establishing a connection with other errors, but I feel like there must be something simple here that I am missing. Also, there is more than one instance of SQLServer Express on my machine. Would removing one help? I've enabled all TCP/IP ports for the current server, and set all ports to 1433

Any advice would be very much appreciated.

1
Are you able to connect via SSMS first off? - Dave Cullum
Also -- try Machinename instead of localhost/127.0.0.1 -- tends to be more reliable. - Dave Cullum
Yes, I am able to connect to SSMS; I've tried my machine name but to no avail. Question: is it possible that because there are two SQL Server instances that it is fudging up the connection? In SSMS, when checking server properties I have one server named MachineName\FirstInstance and another MachineName\SecondInstance. - WakaChewbacca
Yeah, you need to specify the instance name in your connection strings... I don't know node.js well enough to answer that part, but it definitely required. - Dave Cullum
Yeah, same. I have it working in my ASP.NET project, but was hoping to develop a facsimile of sorts using Node.js and Express.js instead of the C# API I currently have. I'll keep trying though. Thanks! - WakaChewbacca

1 Answers

0
votes

Needed to restart my system (Like the scrub I am). Works now. The changes in enabling TCP/IP don't take effect unless system is restarted(which SQL Server Configuration Manager tried to tell me).