Hi guys I have an error on mssql with node.js, the code below performs a select on a Sql Server 2014 database and insert the data into an array! My problem is that in some cases this error occurs: Global connection already exists. Call sql.close() first. How can I resolve this error?
const DbConfig = require('../Config/DatabaseConfig.js'); const sql = require('mssql'); async function RicercaCantiere(NomeCantiere) { var data=[]; await sql.connect(DbConfig.config); const request = new sql.Request(); request.input('NomeCantiere', sql.VarChar, NomeCantiere); const recordset=await request.query("select * from CantiereConsuntivo where NomeCantiere like '%' + @NomeCantiere +'%' "); for(var i=0; i<recordset.recordset.length; i++){ data.push({ IdCantiere: recordset.recordset[i].IdCantiere, IdCliente: recordset.recordset[i].IdCliente, Filiale: recordset.recordset[i].Filiale, RagioneSociale: recordset.recordset[i].RagioneSociale, NomeCantiere: recordset.recordset[i].NomeCantiere, DataCreazioneCantiere: recordset.recordset[i].DataCreazioneCantiere, Tipologia: recordset.recordset[i].Tipologia, StatoCantiere: recordset.recordset[i].StatoCantiere, StatoFatturazione: recordset.recordset[i].StatoFatturazione }) } await sql.close(); return data; } module.exports.RicercaCantiere = RicercaCantiere;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)