2

I have this issue since I uploaded my code on hosting panel, my Database is different server and API is a different server The error is code: "PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR", fatal: false}

it is working for some time but after calling another API then an error is occurring. Here is my code

app.js

var mysql      = require('mysql');

var connection = mysql.createConnection({
  host     : 'xx.xx.xx.xx',
  user     : 'abc',
  password : '123',
  database : 'XYZ',
 });

connection.connect(function(err) {
    if (err) {
      console.error('error connecting: ' + err.stack);
      return;
    }
   console.log('connected as id ' + connection.threadId);
  });

Here is the controller user.js

var mysql      = require('mysql');
   var connection = mysql.createConnection({
      host     : 'xx.xx.xx.xx',
      user     : 'abc',
      password : '123',
      database : 'XYZ',
     })

This is one code snippet of my API.

exports.getLandLord =(req, res, next)=>{
    var sql =`SELECT *FROM  registrations`;
       connection.query(sql, function(error, result, field){
        if(error){
            return res.status(201).json({message:error, status:402, success:false})
        }
        else
        if(result.length>0){
            res.status(200).json({message:"Land Loard List", status:200, success:true, 
          users:result,})
        }
        else
        res.status(200).json({message:"No Record Found ", status:402, success:false, users:result})
    })


}

I tried googling but I was not able to make it fix.

Please can anyone help me with this issue

Your response and help would be highly appreciated

Thanks in advance.

8
  • Is your server running? (e.g node start app.js) Commented Jan 29, 2020 at 6:26
  • Yes it is running in my case it sever.js Commented Jan 29, 2020 at 6:32
  • 1
    Even I testing it with using localhost but online database connection same error occurring after some time later Commented Jan 29, 2020 at 6:33
  • Does this answer your question? Node JS Mysql PROTOCOL ENQUEUE AFTER FATAL ERROR Commented Jan 29, 2020 at 6:34
  • I visited it but unable to implement it Commented Jan 29, 2020 at 6:35

1 Answer 1

2

After struggling for a long time I work around this and got code to work refer NodeJS MySQL - How to know connection is release or not

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.