Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript node js代码中的connection.release()必须有多少连接?_Javascript_Node.js - Fatal编程技术网

Javascript node js代码中的connection.release()必须有多少连接?

Javascript node js代码中的connection.release()必须有多少连接?,javascript,node.js,Javascript,Node.js,我正在为web服务使用节点js,我在代码中使用pool.getConnection(),在使用pool.getConnection()关闭此连接后,我使用connection.release()但在任何查询中,我都不会使用任何函数进行紧密连接。请告诉我此代码是否有效 pool.getConnection(function(err,connection){ connection.release(); if(!err){ email=req.user.email connection

我正在为web服务使用节点js,我在代码中使用
pool.getConnection()
,在使用
pool.getConnection()
关闭此连接后,我使用
connection.release()但在任何查询中,我都不会使用任何函数进行紧密连接。请告诉我此代码是否有效

pool.getConnection(function(err,connection){
connection.release();
if(!err){
    email=req.user.email
    connection.query('select * from users where email=?',[email],
    function(err,user_detail){
        if(!err)
        {
                    connection.query('insert into message(??,time,type,user_id) values(?,?,?,?)',[messagecolumns,dbValues,time,type,user_id],
                                function(err,message_inserted){
                                        if(!err)
                                        {
                                                console.log('Message send',message_inserted.insertId);
                                                connection.query('select u.firstname,u.lastname,u.img_path,m.* from users u, message m where u.id=m.user_id and m.id=?',[message_inserted.insertId],
                                                function(err,message_detail){
                                                        if(!err)
                                                        {
                                                            connection.query('select    count(id) as message_count from message where appointment_request_id=?',[appointment_request_id],
                                                            function(err,total_message){
                                                                if(!err)
                                                                {
                                                                        connection.query('update appointment_request set message_count=? where appointment_request_id=?',[total_message[0].message_count,appointment_request_id],
                                                                        function(err,update_message_count){
                                                                        if(!err)
                                                                        {
        }
    });
 }
else {
   console.log('connection Error',err);
}

我觉得这是无效的连接方法,因为从一些网站上我意识到,SQL查询后,我必须关闭连接,但在这段代码中,我从来没有使用任何关闭连接,我的代码是一段时间给我500服务器错误,一段时间它成功工作,所以我必须修复此错误,我想永久解决,如果有人可以帮助请告诉我这个问题的解决办法。如果您对理解有任何困惑,可以问我。

池的连接数有限()

然后,其中一个连接将从池中删除并传递给您,以便您可以使用它。完成连接后,您将调用
connection.release()
。调用
connection.release()
后,连接将被传递回池中,并可供代码的其他部分自由使用。因此,在调用release之后使用此连接是无效的,因为它可能已关闭或被请求与
getConnection
连接的代码的另一部分使用(在大多数情况下,它可能仍然工作,但可能意外失败)

在代码中调用
connection.release()在回调开始时,因此在
释放之后使用
连接
是无效的


您不能在同一个连接上多次调用
connection.release()

这是有效的
pool.getConnection(函数(err,connection){connection.release();
@Alex这是您问题中的前两行代码!?查询后我必须使用
connection.release();
??