Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
Error: No event 'socketConnect' in state 'SentPrelogin'

I am trying to connect my SQL Server database with node.js using knex but I am facing issue

Error: No event 'socketConnect' in state 'SentPrelogin'
    at Connection.dispatchEvent (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1281:26)
    at Connection.socketConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1303:10)
    at C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1145:12
    at Socket.onConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connector.js:106:7)
    at Socket.emit (events.js:314:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1131:10)
Emitted 'error' event on Connection instance at:
    at Connection.dispatchEvent (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1281:12)
    at Connection.socketConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1303:10)
    [... lines matching original stack trace ...]
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1131:10)
[nodemon] app crashed - waiting for file changes before starting...

My code is

var knex = require('knex')({  
  client: 'mssql',
  version:"7_1",  
   connection: {  
    user: 'sa',  
    password: 'Admin@123',  
    server: 'localhost',  
    database: 'Demo'  
   }  
 });  

 knex.select("*").from("Country")  
 .then(function (depts){  
   depts.forEach((dept)=>{ //use of Arrow Function  
     console.log({...dept});  
   });  
 }).catch(function(err) {  
 // All the error can be checked in this piece of code  
   console.log(err);  
 }).finally(function() {  
   // To close the connection pool  
   knex.destroy();  
 });
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You need to add a missing dependency:

npm install --save tedious

As of knex v0.95.0 you'll need to use the tedious library instead of mssql when connecting to an MSSQL database. According to the knex upgrade instructions:

MSSQL driver was completely reworked in order to address the multitude of connection pool, error handling and performance issues. Since the new implementation uses tedious library directly instead of mssql, please replace mssql with tedious in your dependencies if you are using a MSSQL database.

Installing the package above should resolve your issue. I also had to set the encrypt option to false when connecting to my local database to avoid this error:

ConnectionError: Failed to connect to localhost:1433 - self signed certificate
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda