Skip to content

Connection lost: The server closed the connection - vanilla #1889

@ghost

Description

Hi Doug!
I have the following code:

var mysql = require('mysql');
var con = mysql.createConnection({
  host: "192.168.0.46",
  user: "SHARED",
  password: "Pjh",
  database: "SHARED"
});

con.connect(function(err) {
  if (err) return err;
  con.query("SELECT USERID FROM TBL_USER_LOCAL WHERE USERNAME = 'someuser'", function (err, result, fields) {
    if (err) return err;
    console.log(result);
  });
});

The connection gets closed if the server is offline - I am calling this from a different server than the db is running on. The node server crashes if the above is true. Any ideas how I can keep the node server running (this node server just listens for connections to several mysql servers) and if one is down, this code causes the crash of node.

I hope I have been clear? Thank you!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions