第一次访问时一切正常不会发生错误,刷新之后就会发生如下错误

Error: Cannot enqueue Handshake after invoking quit.

    at Protocol._validateEnqueue (D:CodeWorkspaceexpressmysqlnode_modulesmysqllibprotocolProtocol.js:215:16)

    at Protocol._enqueue (D:CodeWorkspaceexpressmysqlnode_modulesmysqllibprotocolProtocol.js:138:13)

    at Protocol.handshake (D:CodeWorkspaceexpressmysqlnode_modulesmysqllibprotocolProtocol.js:51:23)

    at Connection.connect (D:CodeWorkspaceexpressmysqlnode_modulesmysqllibConnection.js:119:18)

    at D:CodeWorkspaceexpressmysqlsrccomftgcontrollerdept.js:6:8

    at Layer.handle [as handle_request] (D:CodeWorkspaceexpressmysqlnode_modulesexpresslibrouterlayer.js:95:5)

    at next (D:CodeWorkspaceexpressmysqlnode_modulesexpresslibrouterroute.js:137:13)

    at Route.dispatch (D:CodeWorkspaceexpressmysqlnode_modulesexpresslibrouterroute.js:112:3)

    at Layer.handle [as handle_request] (D:CodeWorkspaceexpressmysqlnode_modulesexpresslibrouterlayer.js:95:5)

    at D:CodeWorkspaceexpressmysqlnode_modulesexpresslibrouterindex.js:281:22

Emitted ‘error’ event at:

    at Connection._handleProtocolError (D:CodeWorkspaceexpressmysqlnode_modulesmysqllibConnection.js:426:8)

    at Protocol.emit (events.js:189:13)

    at Protocol._delegateError (D:CodeWorkspaceexpressmysqlnode_modulesmysqllibprotocolProtocol.js:398:10)

    at Handshake. (D:CodeWorkspaceexpressmysqlnode_modulesmysqllibprotocolProtocol.js:232:10)

    at Handshake.emit (events.js:189:13)

    at Handshake.Sequence.end (D:CodeWorkspaceexpressmysqlnode_modulesmysqllibprotocolsequencesSequence.js:78:12)

    at D:CodeWorkspaceexpressmysqlnode_modulesmysqllibprotocolProtocol.js:236:14

    at process._tickCallback (internal/process/next_tick.js:61:11)

连接mysql 然后不断开,一直连着数据库,这样就不会错了,

route_dept.get(‘/show’,function(req,res){

    db.connect();        (把这行移动到方法外)

    db.query(“select * from dept”,function (error,results, fields){

        if(error) throw error;

        var json = {

            code:0

            ,msg:’成功’

            ,data:results

        };

        res.send(json); // send end({aa:123})….

        db.end();  (删除这行)

    });

});

文章来源于互联网:node.js连接mysql报错Error: Cannot enqueue Handshake after invoking quit.

发表评论