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.
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.
Share Improve this question edited Jan 29, 2020 at 6:31 FanoFN 7,1242 gold badges16 silver badges35 bronze badges asked Jan 29, 2020 at 6:07 K.SK.S 4631 gold badge12 silver badges31 bronze badges 8- Is your server running? (e.g node start app.js) – FanoFN Commented Jan 29, 2020 at 6:26
- Yes it is running in my case it sever.js – K.S 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 – K.S Commented Jan 29, 2020 at 6:33
- Does this answer your question? Node JS Mysql PROTOCOL ENQUEUE AFTER FATAL ERROR – Prakash Karena Commented Jan 29, 2020 at 6:34
- I visited it but unable to implement it – K.S Commented Jan 29, 2020 at 6:35
1 Answer
Reset to default 2After 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745428001a4627266.html
评论列表(0条)