0

My current js node code:

const sql = require('mssql')
const sqlConfig = {
  user: 'sa',
  password: '12345678',
  database: 'mementoDB',
  server: 'LAPTOPSZKOLA\\SQLEXPRESS',
  pool: {
    max: 10,
    min: 0,
    idleTimeoutMillis: 30000
  },
  options: {
    encrypt: false,
    trustServerCertificate: true
  }
}

const func = async () => {
 try {
  await sql.connect(sqlConfig);
  const result = await sql.query(`select * from People`);
  console.dir(result);
 } catch (err) {
  console.log(err);
 }
}
func();

My error:

ConnectionError: Failed to connect to LAPTOPSZKOLA\SQLEXPRESS in 15000ms at C:\Users\creat\OneDrive\Pulpit\jsapps\tut2\node_modules\mssql\lib\tedious\connection-pool.js:85:17 at Connection.onConnect (C:\Users\creat\OneDrive\Pulpit\jsapps\tut2\node_modules\tedious\lib\connection.js:838:9) at Object.onceWrapper (node:events:629:26) at Connection.emit (node:events:514:28) at Connection.emit (C:\Users\creat\OneDrive\Pulpit\jsapps\tut2\node_modules\tedious\lib\connection.js:959:18) at Connection.connectTimeout (C:\Users\creat\OneDrive\Pulpit\jsapps\tut2\node_modules\tedious\lib\connection.js:1209:10) at Timeout._onTimeout (C:\Users\creat\OneDrive\Pulpit\jsapps\tut2\node_modules\tedious\lib\connection.js:1154:12) at listOnTimeout (node:internal/timers:573:17) at process.processTimers (node:internal/timers:514:7) { code: 'ETIMEOUT', originalError: ConnectionError: Failed to connect to LAPTOPSZKOLA\SQLEXPRESS in 15000ms at Connection.connectTimeout (C:\Users\creat\OneDrive\Pulpit\jsapps\tut2\node_modules\tedious\lib\connection.js:1209:26) at Timeout._onTimeout (C:\Users\creat\OneDrive\Pulpit\jsapps\tut2\node_modules\tedious\lib\connection.js:1154:12) at listOnTimeout (node:internal/timers:573:17) at process.processTimers (node:internal/timers:514:7) { code: 'ETIMEOUT' } }

My SQL Server:

db structure and working query

2
  • SQL Server Express edition commonly isn't even listening on a TCP port and so could not be connected to from NodeJS processes. Have you opened SQL Server 2022 Configuration Manager and checked the SQL Server Network Configuration of the SQLEXPRESS instance to ensure that the TCP/IP server protocol is enabled? If you make any changes in here you need to restart both the SQLEXPRESS instance as well as the SQL Browser service. Commented Apr 13, 2024 at 13:53
  • I have now enabled TCP/IP and restarted first server then even whole computer but I am still getting timed out error Commented Apr 13, 2024 at 14:32

2 Answers 2

0

".\SQLEXPRESS" or "localhost"

Find out host name by using SELECT @@SERVERNAME

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

2 Comments

SELECT @@SERVERNAME returns same thing I used just in lowercase .\SQLEXPRESS gives error: ConnectionError: getaddrinfo ENOTFOUND . and localhost gives error: ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
@Creatos Check configuration manager: 1.Open SQL Server Configuration Manager and check if the SQL Server instance is running. 2.Ensure the SQL Server Browser service is running. 3.Check the TCP/IP settings. Ensure TCP/IP is enabled and that the port is set correctly.
0

I've got it!! my "SQL Server Browser" service wasn't running. If you are having similar issue you can run this service in "Sql Server Configuration Manager"

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.