PROTOCOL_CONNECTION_LOST Nodejs SQL

时间:2017-08-17 15:53:21

标签: javascript sql node.js connection protocols

我已经检查了我找到的所有答案,但它们对我不起作用。

我突然发现以下错误,因此我的NodeJ无法连接到SQL数据库。

  

PROTOCOL_CONNECTION_LOST

我需要你的帮助。 这是简单的代码:

var path = require('path');
var mysql      = require('mysql');
var express      = require('express');
var fs = require('fs');
app = express();

//Connection to nagios
var connection1 = mysql.createConnection({
host     : 'md1dk69c.propa.net',
user     : 'userName',
password : 'pswd',
database : 'dbName',
port: 5468,
timezone:  'Europe/Berlin'

});

connection1.connect(function(err){
if(!err) {
    console.log("Database is connected ... nn");    
} else {
    console.log("Error connecting to database ... nn"); 
    console.log("code: ",err.code); 
    console.log("fatal: ",err.fatal);    
    console.log("sql: ",err.sql);   
    console.log("sqlMessage: ",err.sqlMessage);   
}
});

app.use(express.static('view'));
app.get("/",function(req,res){
res.sendFile(path.join(__dirname + '/view/proj.html'));
});


app.get("/page",function(req,res){
var sql1 ='SELECT xxx...';
connection1.query(sql1 , function(err, rows, fields) {

  if (!err)
    {  res.end(JSON.stringify(rows));
    console.log('I am still connected to Database..');
    }
  else 
    {
        console.log('Error while performing the Query.');
        connection1.end();

    }
 });
});
app.listen(3000);

我得到输出:

Error connecting to database ... nn
code:  PROTOCOL_CONNECTION_LOST
fatal:  true
sql:  undefined
sqlMessage:  undefined

0 个答案:

没有答案