SQL EF datacontext Muti thread Problem

Source: Internet
Author: User

Http://www.sqlservercentral.com/Forums/Topic728749-149-1.aspx#bm802921

 

 

Hi,

Recently I 've started getting the following severity 20 error quite often on My SQL 2005 box:
The server will drop the connection, because the client driver has sent multiple requests while the session is in single-user mode. this error occurs when a client sends a request to reset the connection while there are batches still running in the session, or when the client sends a request while the session is resetting a connection. please contact the client driver vendor.

Currently I'm getting around und 30 of these a day, so unfortunately it's not a single occurrence. we have a number of relatively high load websites in front of the database, all of them running ASP. net 3.5 accessing the database through LINQ to SQL and sqlcommands directly. we do not use Mars explicitly, though I suspect that datacontext might do so internally. I have neither explicitly enabled nor disabled Mars in the connection string, so I 'd assume it woshould default to not being enabled. i'm preparing to push out an update that explicitly disables Mars so I can rule that out. all my Googling yielded rather useless results, only referencing Mars as a possible reason.

I 've also had a couple of cases where my ASP. NET apps broke down whenever they tried to contact the database with the following error:
"Executereader requires an open and available connection. The connetion's current state: broken"

So apparently a connection had broken (possible due to the error received on the DB end), even though it was still available in the connection pool. clearing the connection pool solved this issue. I 've only seen this error once, so it may not be correlated-it did happen after I started authentication ing the DB error however.

The Errors seem to occur more often during daytime/highest load, so it's definitely affected by load levels.

Besides disabling Mars and seeing if it has a result, I 've considered setting up a serverside trace and let it run till I get one of the errors and see if I can trace down the affected process and hopefully see the sequence leading up to the error. any suggestions as to how I may track down why this is happening?

A couple of counters to give you an idea of the load/box:
Databases :~ 170
Transactions/sec :~ 800-1300
Logical connections :~ 600
User connections :~ 450-500
Total memory :~ 6, 5 GB
Page life expectancy :~ 23 K

Tcpv4 (as the Google results also suggest this might be a network issue ):
Connection failures :~ 47 K
Connections active :~ 59 K
Connections established :~ 500
Connections passive: 550 K
Connections Reset :~ 16 K
SEG/sec :~ 1000-1500
SEG retransmitted/sec :~ 10

Mark S. Rasmussen
Blog: Improve. dk
Twitter: @ improvedk

Internals geek & author of orcamdf

 

 

I ended up fixing this the hard way that I 'd got Ed to avoid.

I was storing my datacontext in httpcontext. current. items. since I did not do any explicit threading during my request, there shouldn't be any concurrent accesses to the same datacontext. although IIS may switch thread during a request, it still shocould not cause concurrent usage of the DC.

while I have not found out how, the problem vanished as soon as I started instantiating my DC's as needed and not sharing it in any way during the request. somehow multiple threads must have used the same DC and thereby processing ing and sending errant messages to/from the SQL server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.