Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (13.1k points)
edited by

I have a database in Azure SQL, and developed a rest API in node.js. Whenever I was using SWORM npm package for connecting Azure SQL Database it is throwing an error:

"message": "Failed to connect to undefined:1433 - connect ECONNREFUSED 127.0.0.1:1433", "code": "ESOCKET"

Can anyone help me with this? Why it is showing this error?

1 Answer

0 votes
by (26.7k points)

To rectify this error, please try the below code which will help:

var sworm = require('sworm');

var db = sworm.db();

db.connect({

  driver: 'mssql',

  config: {

    user: '<user>@<server>',

    password: '<password>',

    server: '<server>.database.windows.net',

    database: '<database>',

    options: {

        encrypt: true // Use this if you're on Windows Azure

    }

  }

}).then(()=>{

    db.query('select 1 as number').then((results)=>{

        console.log(results);

    })

})

I hope this will help.

Want to become an Azure expert? join azure master program now!!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...