2

I am using Knex.js to connect Sql server using Node.js. Here is what i tried so far

  1. npm init
  2. npm install knex --save
  3. npm install mssql -g
  4. nodemon index.js

and index.js file have

 var knex = require('knex')({  
 client: 'mssql',  
 connection: {  
  user: 'sa',  
  password: 'Password@123',  
  server: 'manikant/SQLEXPRESS',  
  database: 'myDb' ,
  options: {
    port: 1433
   } 
  }  
}); 

  app.get('/getData',(req,res)=>{
   const data = {};
   knex.select("*").from("usr")  
   .then(function (depts){  
   depts.forEach((dept)=>{ //use of Arrow Function  
    console.log({...dept}); 
    data = {dept}
     });  
   }).catch(function(err) {  
    console.log(err);  
   }).finally(function() {  
   knex.destroy();  
   });  
  res.json({data})

 })

But getting errors message: 'Failed to connect to manikant/SQLEXPRESS:1433 - getaddrinfo ENOTFOUND manikant/SQLEXPRESS', code: 'ESOCKET' },

TCP/IP protocol is enabled on port 1433 and Sql server browser is running. followed similar question on SO Note:- Able to connect with java application.So seems like problem with knex only.

manikant gautam
  • 3,521
  • 1
  • 17
  • 27

0 Answers0