Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda