0

I am getting this error while connecting to "azure mysql" database using "mysql" package in nodejs.

Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:209:20) -------------------- at Protocol._enqueue (C:\Users\AMEY\Documents\MCA Projects\Email Portal\email-portal-backend\node_modules\mysql\lib\protocol\Protocol.js:141:48) at Protocol.handshake (C:\Users\AMEY\Documents\MCA Projects\Email Portal\email-portal-backend\node_modules\mysql\lib\protocol\Protocol.js:52:41) at Connection.connect (C:\Users\AMEY\Documents\MCA Projects\Email Portal\email-portal-backend\node_modules\mysql\lib\Connection.js:130:18) at Object. (C:\Users\AMEY\Documents\MCA Projects\Email Portal\email-portal-backend\index.js:52:7) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) at internal/main/run_main_module.js:17:47 { errno: -4077, code: 'ECONNRESET', syscall: 'read', fatal: true }

Here's my code with createConnection:

const conn2 = new mysql.createConnection({
    host: "*****.database.windows.net",
    port: 1433,
    user: "ameykhoje",
    password: "******",
    database: "dbname",
    ssl: true,
    debug: true })
conn2.connect((err) => {
if(err) {
    console.log(err)
}
else {
    console.log("connected to azure")
    app.listen(port, () => {
        console.log(`Connected to database`);
    });
}})

I have tried same this with createPool also. But didn't worked.

i have also updated mysql package in package.json to:

"mysql": "git://github.com/mysqljs/mysql#e3e123e9af7c0829a6c1417d911572a75b4a5f95"

Please help me to solve this

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Amey Khoje
  • 43
  • 4
  • Does this answer your question? [ECONNRESET error crashing NodeJS application](https://stackoverflow.com/questions/62416274/econnreset-error-crashing-nodejs-application) – Luuk Apr 11 '21 at 12:15
  • [Nothing here?](https://www.google.com/search?q=ECONNRESET+azure+site:stackoverflow.com) or [here](https://www.google.com/search?q=read+ECONNRESET+at+TCP.onStreamRead+site:stackoverflow.com) - please always start by googling the error – mplungjan Apr 11 '21 at 12:15
  • I have tried but don't know why getting this error. I can connect to my local mysql db, but when i try to connect to azure it throws this error. – Amey Khoje Apr 11 '21 at 12:28
  • Are you connecting to a MySQL database or SQL database? – Gaurav Mantri Apr 11 '21 at 12:29
  • SQL Databases.. – Amey Khoje Apr 11 '21 at 12:34
  • Then why are you using `mysql` node package? Shouldn't you be using `mssql` package? – Gaurav Mantri Apr 12 '21 at 01:11

2 Answers2

0

It seems more like your DB is not allowing access, have you tried to check the ACL on Azure to ensure you are allowing connections from your host?

proxim0
  • 1,418
  • 2
  • 11
  • 14
0

I believe the issue is coming because of incorrect node package. You're using mysql node package to connect to an Azure SQL database.

You will need to use mssql node package.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241