0
votes

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

2
Does this answer your question? ECONNRESET error crashing NodeJS application - Luuk
Nothing here? or here - please always start by googling the error - mplungjan
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
Are you connecting to a MySQL database or SQL database? - Gaurav Mantri
SQL Databases.. - Amey Khoje

2 Answers

0
votes

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?

0
votes

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.