Getting a website error when multiple users access the same page at the same time

I get the following error message on an ASP.NET 4 website when multiple users access the same page:

Failed to open base provider. in System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf etc ...

I am using Entity Framework 4 to access a SQL Server 2008 database.

Sometimes this page works, so I know that the connection string is correct. In addition, the database is set to multi-user mode, and my MARS is set to true in the connection string.

Also in the event viewer, I sometimes get a SQL Server message:

The server will disconnect the connection because the client driver has sent several requests during a single-user session.

As I said, this only happens if I try to access the same page simultaneously on two different computers, simply by refreshing the page or by clicking the same link.

Any help would be greatly appreciated.

Connection strings are added (the first for ASPNETDB and the second for the main database):

<add name="ApplicationServices" connectionString="Data Source=MyServer;Initial Catalog=MyDB;Integrated Security=False;Persist Security Info=False;User ID=****;Password=****;Connect Timeout=120" /> <add name="MyDBEntities" connectionString="metadata=res://*/App_Code.MyDBModel.csdl|res://*/App_Code.MyDBModel.ssdl|res://*/App_Code.MyDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyServer;Initial Catalog=MyDB;Integrated Security=False;User ID=****;Password=****;Connect Timeout=120;User Instance=false;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /> 

The class I used to access the context is as follows:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using MyDBModel; using System.Web.Security; /// <summary> /// Summary description for MyDataAccess /// </summary> public static class MyDataAccess { // Private Class Members //----------------------------------------------------------------------------------------- private static MyDBModel.MyDBEntities dal = new MyDBModel.MyDBEntities(); // Class Constructor / Destructor //----------------------------------------------------------------------------------------- static MyDataAccess() { // Set Entity ObjectContext Merge Options - this basically ensures database items aren't cached dal.NEWS.MergeOption = System.Data.Objects.MergeOption.OverwriteChanges; dal.NEWS_IMAGES.MergeOption = System.Data.Objects.MergeOption.OverwriteChanges; } // Public Methods for Data Access //----------------------------------------------------------------------------------------- /// <summary> /// Get All Current News Items /// </summary> public static List<NEWS> GetCurrentNewsItems() { var items = from news in dal.NEWS where news.NEWS_ACTIVE == true && news.NEWS_STARTDATE <= DateTime.Today && news.NEWS_EXPIRYDATE >= DateTime.Today orderby news.NEWS_DATE descending select news; return NewsManager.GetMyNewsItems(items).ToList(); } } 

Then on my .aspx.cs page I would use something like:

 var news = MyDataAccess.GetCurrentNewsItems(); 
+1
sql-server entity-framework-4
source share
1 answer

I believe your problem is caused by saving the ObjectContext in a static variable.

from the msdn documentation of the ObjectContext Class

The ObjectContext class is not thread safe. The integrity of these objects in an ObjectContext cannot be provided in multi-threaded scripts.

+6
source share

All Articles