Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!