0

I am facing problems while execution of multiple stored procedures using npm-mssql package in expressJS.

Currently i have used SingleTon Design pattern for DB configuration and assigned the connection to an global variable called _config

Well to test the _config connection. I have created an separate route, the output of that particular connection string would like this:

enter image description here

Then in our dashboard, we are calling multiple stored procedures as an service, after the first stored procedure call, the global connection parameters would update like:

enter image description here

Then soon after the execution of this SP asynchronously, there is another SP calling and that gets fail in execution and its parameters are updated like this:

enter image description here

If you closely observe this, the last Stored procedures parameters were not cleared and it throws error like:

enter image description here

So manually before execution i was trying to clear the global _config params as:

enter image description here

I tried this clearing of inputs in so many places like in its particular routes and also before and after execution of stored procedure calls, but still not success. What am i doing wrong? In which place i have to clear this params exactly or do i need to close the sql connection. But everything works async, confused where and how to close. Do i need to open this in separate sockets or how? Any suggestions would be very helpful.

Mithun Shreevatsa
  • 3,588
  • 9
  • 50
  • 95
  • Am i the only one facing this issue? nobody has faced it...? – Mithun Shreevatsa Feb 20 '15 at 09:59
  • better late than never: is it possible your issue is that you're trying to use one global connection across the entire application? singletons with state are not known to place nicely with asynchrony. Just because JavaScript is built from the ground up to use asynchonous operations does not mean it is immune to race conditions and or data corruption. – Dan Jul 06 '15 at 13:30

0 Answers0