Mssql cause node.js instance exit after a few queries
See original GitHub issueHi,
First, thank you for the job you have done with this it looks great !
But I am having a little issue querying database a few times in a row :
Here is the code
try {
var timeOutCallback = function() {
var config = {
"user": "msq2RTFlow",
"password": "msqService4RTFlow",
"server": "localhost",
"database": "MSQ"
};
var connection = new mssql.Connection(config);
connection.connect().then(function() {
var request = new mssql.Request(connection);
request.query('SELECT * FROM Patient;').then(function(recordset) {
console.log(recordset.length);
connection.close();
timeoutId = setTimeout(timeOutCallback, 1000);
}).catch(function(err) {
console.log(err);
connection.close();
timeoutId = setTimeout(timeOutCallback, 1000);
});
}).catch(function(err) {
console.log(err);
connection.close();
timeoutId = setTimeout(timeOutCallback, 1000);
});
};
var timeoutId = setTimeout(timeOutCallback, 1000);
} catch (p_error) {
console.log(p_error);
}
I took the code to query databasase directly from exemples using promises. Even if I’m not using promises, I am experiencing the same issue. I Am not having neither of my error logs in console, I’m having 7 results from query, ten times, then it stops with no message or error at all.
Issue Analytics
- State:
- Created 8 years ago
- Comments:12
Top Results From Across the Web
node-mssql | Microsoft SQL Server client for Node.js
In practice, once the pool is created then there will be no delay for the next connect() call. Also notice that we do...
Read more >my nodejs script is not exiting on its own after successful ...
I just went through this issue. The problem with just using process.exit() is that the program I am working on was creating handles, ......
Read more >Top 10 Most Common Node.js Developer Mistakes - Toptal
exports” and “exports” is very important, and is often a cause of frustration among new Node.js developers. Mistake #6: Throwing Errors from Inside...
Read more >Process | Node.js v19.3.0 Documentation
The Node.js process will exit immediately after calling the 'exit' event listeners causing any additional work still queued in the event loop to...
Read more >Node.js with MySQL - w3resource
var userId = 'some user provided value'; var sql = 'SELECT * FROM users WHERE id = ' + connection.escape(userId); connection.query(sql, function ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The following pattern will give you an existing connection/pool when available, as well as support closing, which will kill the handle to the pool, and connection.
IMHO, this should really be the default behavior… why the connection callback doesn’t return the connection is beyond me… also, that there isn’t an internal pool-list is a bit odd too, imho. I’m doing something similar for mssql-ng, which wraps this library with a template processor for parameterized queries.
Pooling and individual connection lifecycle management has been improved in recent releases so I’m closing this in the hope that upgrading to the latest version resolves the matter.