Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js MSSQL tedius ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED

I am trying to connect to MSSQL 2012 using NodeJS with the mssql connection interface.

When attempting to connect I get the following error:

{ [ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED]
  name: 'ConnectionError',
  message: 'Failed to conncet to localhost:1433 - connect ECONNREFUSED',
  code: 'ESOCKET' }

Any ideas on how to fix this?

like image 622
Matt Carrier Avatar asked Aug 29 '14 22:08

Matt Carrier


People also ask

How do I enable TCP IP in SQL Server Management Studio?

Enable TCP/IP in the SQL ServerExpand the Configuration Tools subfolder and right-click on SQL Server Configuration Manager. Click on Run as Administrator. Select SQL Server Network Configuration and click Protocols for SMTKINGDOM. In the right pane, right-click TCP/IP and click Enable.

How do I enable SQL Server Browser?

To start SQL Server Browser ServiceRight-click SQL Server Browser, and then choose Properties. On the Service tab of the SQL Server Browser dialog box, set the Start mode to Automatic. Choose OK to return to the SQL Server Configuration Manager main page. Right-click SQL Server Browser again, and then choose Start.

Where is SQL Server network configuration?

In SQL Server Configuration Manager, in the console pane, expand SQL Server Network Configuration. In the console pane, click Protocols for <instance name>.

What does the SQL Server Browser service do?

SQL Server Browser listens for incoming requests for Microsoft SQL Server resources and provides information about SQL Server instances installed on the computer. SQL Server Browser contributes to the following actions: Browsing a list of available servers. Connecting to the correct server instance.


3 Answers

The solution is to enable TCP connections which are disabled by default.

enter image description here

like image 107
Matt Carrier Avatar answered Oct 18 '22 18:10

Matt Carrier


My case wasn't exactly the same as Matt's, but his screenshot was enough to remember me what was missing.

enter image description here

As it is said here, when you are using the SQL Server Instance Name to connect to it, you must have SQL Server Browser running.

options.instanceName

The instance name to connect to. The SQL Server Browser service must be running on the database server, and UDP port 1434 on the database server must be reachable.

(no default)

Mutually exclusive with options.port.

like image 34
MMalke Avatar answered Oct 18 '22 17:10

MMalke


If after enabling the TCP connection and your configuration is still not working. Here's my own-configuration.

var config = {
    "user": 'admin',
    "password": 'password',
    "server": 'WINDOWS-PC',
    "database": 'database_name',
    "port": 61427, // make sure to change port
    "dialect": "mssql",
    "dialectOptions": {
        "instanceName": "SQLEXPRESS"
    }
};
like image 21
Player1 Avatar answered Oct 18 '22 16:10

Player1