title: Losing connection with SQL Sever and Node on API request
body: <p>I am trying to loop a query to get results of a given size and after I make the first query it gives me an error</p>
  
  <p>I have tried to reopen the connection which it tells me it's already open and when I try to just use the first connection it says it is closed </p>
  
  <pre><code>axios.defaults.headers.common['X-API-KEY'] = apiKey;
  axios.defaults.headers.common['Content-Type'] =  'application/json';
  axios.defaults.baseURL = 'https://v2.namsor.com/NamSorAPIv2';
  
  const selectStatment = "SELECT [CandidateId] AS id, ( CASE LEN(REPLACE([CandidateName],' ','')) WHEN LEN([CandidateName]) - 1 then PARSENAME(REPLACE([CandidateName],' ','.'), 2) ELSE PARSENAME(REPLACE([CandidateName],' ','.'), 3) END ) AS firstName, PARSENAME(REPLACE([CandidateName],' ','.'), 1) AS lastName ";
  const cleanWherequery = 'WHERE NOT firstName IS NULL OR NOT firstName IS NULL ANd NOT lastName IS NULL';
  const sqlTable = '##apiTable';
  const tempQuery = `DROP TABLE IF EXISTS ##apiTable, ##clean; ${selectStatment} INTO ##clean FROM [dbo].[DimCandidate]; SELECT * INTO ${sqlTable} FROM ##clean ${cleanWherequery}`;
  const orderByFetch= `ORDER BY lastName DESC OFFSET ${i * 100} FETCH NEXT 100`
  const countQuery = `SELECT COUNT(*) AS Count FROM ${sqlTable}`
  
  const conn = new sql.ConnectionPool(dbConfig);
  
  conn.connect()
  .then(function(){
    const reqCount = new sql.Request(conn);
  
    reqCount.query(`${countQuery}`)
    .then(function(recordset){
      let opt = recordset.recordset[0]['Count'];
      let segCount = Math.ceil(opt/100);
      console.log(segCount);
      return segCount;
      sql.close()
    })
    .then(function(count){
      conn.connect()
      .then(function(){
        const req = new sql.Request(conn);
        for(let i = 0; i &lt; count; i++){
          req.query(`SELECT TOP 201 id, firstName, lastName FROM ${sqlTable} ${orderByFetch}`)
          .then(function (recordset) {
            for(i = 0; i &lt; count; i++){
              console.info(recordset.recordset);
              const jsonSet = {
                'personalNames': recordset.recordset
              }
              console.log(jsonSet);
              getRace(jsonSet);
              getGender(jsonSet)
            }
          }).catch(e =&gt;{
            console.log(e);
          })
        }
    })
  }).catch(function (err) {
      console.log(err);
      conn.close();
    })
  })
  .then(function(){
    conn.close();
  })
  .catch(err =&gt; {
    console.log(err);
    conn.close()
  })
  .catch(function(e){
    console.log(e);
  })
  </code></pre>
  
  <p>The expected out come is to loop through the query and make a api request and the current problem is making the second query</p>