In my application, I am querying multiple SQL Servers to return some data. In my main function, I am iterating through the SQL Servers and on each of them, I am iterating through the queries that are supposed to run to fetch the data. When querying the SQL Server for data, I am using a connection promise returned by the following function.
function poolIt (sqlQuery,sqlServer,databaseName) {
if(!connection)
{
//sqlServer_temp = sqlServer
//instead of checking if connection is defined
//we have to check if connection is open
var dbConfiguration = {
driver: 'msnodesqlv8',
server: sqlServer,
database: databaseName,
options: {
trustedConnection: true
}
}
connection = sql.connect(dbConfiguration);
}
}
Now when the loop is done for one SQL Server, it should connect to another SQL Server. But when the debug mode is on, I see that all the queries are running against only one server. I understand that this is because of the above function as it is checking if a connection object is available or not before creating a new connection. So, my question is on how to kill the connection object? connection.close() is not working and nor does sql.close()
Any help, please ?