CopyPastor

Detecting plagiarism made easy.

Score: 0.8105399012565613; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2017-09-17
by Reza Mousavi

Original Post

Original - Posted on 2013-11-26
by CloudyMarble



            
Present in both answers; Present only in the new answer; Present only in the old answer;

It seems your code is working correctly as you mentioned before, I suggest to the method:
1-Change connection idle timeout on your Mysql server.(prevent disconnect)
2-Send keep alive or simple query every hour.
Finally, change your code to reconnect each time you disconnected.


var db_config = { host: 'localhost', user: 'root', password: '', database: 'example' }; var connection; function handleDisconnect() { connection = mysql.createConnection(db_config); // Recreate the connection, since // the old one cannot be reused. connection.connect(function(err) { // The server is either down if(err) { // or restarting (takes a while sometimes). console.log('error when connecting to db:', err); setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect, } // to avoid a hot loop, and to allow our node script to connection.query("SELECT * FROM Mytable",function(err, rows, fields) { // Get your query result here }); }); // process asynchronous requests in the meantime. // If you're also serving http, display a 503 error. connection.on('error', function(err) { console.log('db error', err); if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually handleDisconnect(); // lost due to either server restart, or a } else { // connnection idle timeout (the wait_timeout throw err; // server variable configures this) } }); } handleDisconnect();


Try to use [this code][1] to handle server disconnect:
var db_config = { host: 'localhost', user: 'root', password: '', database: 'example' }; var connection; function handleDisconnect() { connection = mysql.createConnection(db_config); // Recreate the connection, since // the old one cannot be reused. connection.connect(function(err) { // The server is either down if(err) { // or restarting (takes a while sometimes). console.log('error when connecting to db:', err); setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect, } // to avoid a hot loop, and to allow our node script to }); // process asynchronous requests in the meantime. // If you're also serving http, display a 503 error. connection.on('error', function(err) { console.log('db error', err); if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually handleDisconnect(); // lost due to either server restart, or a } else { // connnection idle timeout (the wait_timeout throw err; // server variable configures this) } }); } handleDisconnect();
In your code i am missing the parts after `connection = mysql.createConnection(db_config);`
[1]: https://github.com/felixge/node-mysql#server-disconnects

        
Present in both answers; Present only in the new answer; Present only in the old answer;