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?
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.
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.
In SQL Server Configuration Manager, in the console pane, expand SQL Server Network Configuration. In the console pane, click Protocols for <instance name>.
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.
The solution is to enable TCP connections which are disabled by default.
My case wasn't exactly the same as Matt's, but his screenshot was enough to remember me what was missing.
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.
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"
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With