6

I want to use a mssql database for my project. I took the node-mssql module (https://www.npmjs.com/package/mssql) and for the database management I use Microsoft SQL Server Management Studio 17.

When executing some queries I don't want to connect to the database multiple times so I want to create a pool to have a permanent connection to the database.

My database manager module:

const sql = require('mssql');
const db = require('../config/database.js');
const pool = new sql.ConnectionPool(db).connect();

My database configuration:

module.exports = {
    user: process.env.DB_USER || 'sa',
    password: process.env.DB_PASS || '-- myPassword --',
    server: process.env.DB_SERVER || 'localhost',
    database: process.env.DB || 'local_demo_cobra',
};

MSSQL Studio I changed the authentication mode to SQL Server Authentication

enter image description here

and here you can see the database managed by the server

enter image description here

When trying to run the code I get the error

ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)

The database is running on my own system so using localhost should be fine. I also tried to change the server configuration to

server: process.env.DB_SERVER || 'localhost\\AP-MHERMSEN',

but this throws the same error

ConnectionError: Failed to connect to localhost\AP-MHERMSEN

What is wrong or missing?

1 Answer 1

1
+50

understand that you trying to connect to newly installed MSSQL locally. May you please check the below:

  1. Ensure firewall port 1433 is open and listening. How to check > From CMD, type netstat -an

  2. Launch SQL Server Configuration Manager, Expand SQL Server Network Configuration, Right-click Protocols for SQLEXPRESS, Right-click TCP/IP (ensure this is enabled), Under Tab IP Addresses, scroll down look for IPAll at the bottom, Ensure TCP Port is configured to 1433.

  3. Ensure SQL Browser service is running.

Let me know if you stuck in any steps.

Sign up to request clarification or add additional context in comments.

3 Comments

Hey there, thanks for your response. I added Port 1433 to my firewall. I enabled TCP/IP via Configuration Manager and the SQL Browser is set to automatic. But I can't find the Tab IP / IPALL
Please use below link and assign the port.Scroll down the TCP/IP Properties>IP Addresses tab until bottom. blog.sqlauthority.com/2018/07/24/…
Still same? Did you try restart the service before re-try again?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.