Cant access Azure SQL server from nodejs

I am trying to do a simple query to my azure SQL server from NodeJs, im getting errors that i cannot connect to the server. all the details are correct because i used them on another application i built in C#.

my code:

var mysql = require('mysql');

var config =
    host: Server,
    user: UserName,
    password: PassWord,
    database: Database

const conn = new mysql.createConnection(config);

    function (err) { 
    if (err) { 
        console.log("!!! Cannot connect !!! Error:");
        throw err;
       console.log("Connection established.");

function queryDatabase(){
    conn.query('SELECT * FROM Drinks', function (err, results, fields) 
        if (err) throw err; 

    conn.end(function (err) { 
    if (err) throw err;
    else  console.log('Done.') 

I have tried making port rules, allowing nodejs through firewall, turning off firewall, I have added my IP to the firewall on the azure group and still cant connect. Any help would be awesome. Thanks!


Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:211:20)
    at Protocol._enqueue (C:\node\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (C:\node\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at Connection.connect (C:\node\node_modules\mysql\lib\Connection.js:116:18)
    at Object.<anonymous> (C:\node\test.js:14:6)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read',
  fatal: true

75 thoughts on “Cant access Azure SQL server from nodejs”

Leave a Comment