0

I am using asp.net with web api. In my project there is a message page which is accessible to all guests. This message page will get automatically refreshed for all guests using signalR if there is message for all guests.

But some of the guests are getting an error on the message page as all guest pages are refreshing at the same time. so in code behind same function(which is responsible for getting the messages from database) is called simultaneously some message for some guest retrieved properly but for some other guests reader is getting closed before retrieving the messages.

Ahsan
  • 2,488
  • 2
  • 22
  • 44

1 Answers1

0

Reason for the issue:

Due to the use of "application.Application.Add(requestUrl, clientDatabase)" This was adding the database in application variable there for same database connection is used throughout the application scope. So while doing some simultaneous requests to database same connection was used and any of the request causes the connection to be closed resulted in error for other request which were in the middle of execution.

eg Send message to all guest causes all guests message window to be refreshed. In refreshing we are fetching the messages from database for all the guest. so there were simultaneous requests if any one completes the message fetching then it closes the connection since the same connection was being used by other requests too, other requests gets the error

Resolution:

Rather than adding the database in "application.Application.Add(requestUrl, clientDatabase)" we will add in the "application.Context.Items.Add(requestUrl, clientDatabase)". This makes the database persist for the single HTTP request only.

Reference URLs

Usage of using keyword http://www.c-sharpcorner.com/article/leveraging-the-using-keyword-in-C-Sharp/ http://www.codeproject.com/Articles/442069/ASP-NET-How-To-Use-Open-Close-Connections-Correctl

Command Behavior details https://msdn.microsoft.com/en-us/library/system.data.commandbehavior(v=vs.110).aspx

Determine total number of open/active connections How to determine total number of open/active connections in ms sql server 2005

Connection pools details https://www.pythian.com/blog/sql-server-understanding-and-controlling-connection/

HttpContext.Current.Items http://www.codeproject.com/Articles/146455/When-can-we-use-HttpContext-Current-Items-to-store

HttpContext.Current.Application http://forums.asp.net/t/1378763.aspx?Need+to+understand+HttpContext+Current+Application http://www.codeproject.com/Articles/87316/A-walkthrough-to-Application-State

Connection pools using performance counter

http://www.c-sharpcorner.com/uploadfile/CMouli/monitoring-database-connections-using-performance-counters/

Performance Counters in ADO.NET

https://msdn.microsoft.com/en-us/library/ms254503(v=vs.110).aspx

Give performance counter access on IIS server

"Access to the registry key 'Global' is denied" when accessing performance counters

Community
  • 1
  • 1