How can I keep the connection of sql server? #11

brianwang opened this Issue Dec 24, 2013 · 5 comments


None yet
3 participants

I start a new server connected to the database server, after a long time no connections to db, when reconnect it, the app idled.

Can you add a 'error' or 'timeout' event for connection that we can use it.

Thank you so much.

@patriksimek patriksimek added a commit that referenced this issue Jan 6, 2014

@patriksimek patriksimek 0.4.2 - #10 #11 #12
[new] Added connection timeout for node-tds
[fix] Module now handle tedious network errors correctly
[fix] Connection pool now destroy failed connections correctly
[fix] Connection to instance name via tedious now works correctly
[change] Option 'timeout' is now common option for all drivers (see

patriksimek commented Jan 6, 2014

I'am not sure what exactly you are talking about. I have made some changes in 0.4.2 - module now can handle tedious network errors correctly. I hope it resolve you problem.

jlertle commented Jan 14, 2014

This is a great module! Love what you have done so far ;-)

I do have the same request as op. If the connection sits idle for a a period of time it will disconnect and on the next call have to be re-established. This can make a 63ms request take over 1000ms as it reconnects.

I thought about just having a "keep alive" query that runs in the background every 2-3 seconds but wondered if there was a cleaner way to handle this. Any ideas?


patriksimek commented Jan 14, 2014


There is a clear way to do it - simply initialize Connection with pool.min option set to 1 (or higher). It means, that there must be at least one active connection in the pool. Higher number means more concurrent active connections.


var connection = new sql.Connection({
    user: '...',
    password: '...',
    server: 'localhost',
    database: '...',
    pool: {
        min: 5

Hope it helps.

jlertle commented Jan 17, 2014

Thx! Not sure how I missed that.


patriksimek commented Jan 25, 2014

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment