title: Connecting SQL Database from NodeJs - ConnectionError: Connection not yet open
body: <p>I am trying to connect SQL database from NodeJs, but getting this error:
  <strong>Error while querying database :- ConnectionError: Connection not yet open.</strong></p>
  
  <pre><code> var executeQuery = function(res, query) { 
     var conn = new sql.ConnectionPool(dbConfig);
  
     conn.connect().then(function () {
       // create Request object
       var request = new sql.Request(conn);
       // query to the database
       request.query(query, function (err, queryResult) {
         if (err) {
           console.log("Error while querying database :- " + err);
           res.send(err);
         } else {
           res.send(queryResult);
         }
       });
  
       conn.close();
     })
  }
  </code></pre>
  
  <p>Please help.</p>
  
  <p>Thank You
  James</p>