From 39ac9b887e0fbf98b0c53d1c37b75383d6458ecf Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 1 Jan 2023 22:27:14 +0800 Subject: [PATCH] Fix #2504 --- server/util-server.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index 2ce6de3ee..ffd171b40 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -248,19 +248,19 @@ exports.dnsResolve = function (hostname, resolverServer, resolverPort, rrtype) { * @param {string} query The query to validate the database with * @returns {Promise<(string[]|Object[]|Object)>} */ -exports.mssqlQuery = function (connectionString, query) { - return new Promise((resolve, reject) => { - mssql.connect(connectionString).then(pool => { - return pool.request() - .query(query); - }).then(result => { - resolve(result); - }).catch(err => { - reject(err); - }).finally(() => { - mssql.close(); - }); - }); +exports.mssqlQuery = async function (connectionString, query) { + let pool; + try { + pool = new mssql.ConnectionPool(connectionString); + await pool.connect(); + await pool.request().query(query); + pool.close(); + } catch (e) { + if (pool) { + pool.close(); + } + throw e; + } }; /**