简体   繁体   中英

Trouble connecting to SQL Server Express with Node.js

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM