Error: Global connection already exists. Call sql.close() first.
See original GitHub issueI’m wrestling with an aws lambda and mssql.
It seems like there’s some kind of error event that exits but doesn’t close the connection, so the next request is met with:
Error: Global connection already exists. Call sql.close() first.
From here
It seems important to be able to check for the existence of globalConnection, but there doesn’t seem to be a getter, correct? Something like the following would help:
// Turn off this error and just return the existing globalConnection
sql.connect({ reuseConnection: true })
sql.connect()
// Just a getter for globalConnection
sql.getConnection()
if (sql.connectionStatus() === CONNECTED) { ... }
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:9
Top Results From Across the Web
node.js Global connection already exists. Call sql.close() first
You have to create a poolConnection try this: new sql.ConnectionPool(config).connect().then(pool => { return pool.request().query("SELECT ...
Read more >Error: Global connection already exists. Call sql.close() first
close() first. node.js. Hi I am creating node js restful api by using sqlserver database , i prepare get api ...
Read more >MSSQL not close connection of database - CodeProject
My problem is that in some cases this error occurs: Global connection already exists. Call sql.close() first. How can I resolve this error?...
Read more >[Solved]-Global connection already exists issue node.js-node.js
I was facing the same issue and solved it with below implementation, For handling global connection already exists. call sql.close() first we need...
Read more >patriksimek/node-mssql - Gitter
“Connection is closed” errors are only received when the connection is not yet established or already closed (explicitly by calling close ).
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
I got
connectionStatus is not a function
error, I use the code below instead:I’m really in two minds about this.
getConnection
function for accessing the global connection for fear of making it appear acceptable to use.However, I can see how it would be useful, maybe
connect
should just return the existing connection if it exists instead of erroring?