Entity Framework with multiple web users

V

Vitoman

Our department is currenly testing a web application that utilizes the
Entity Framework. After installing the application on IIS it works as
expected with one user but as soon as 2 people start working the same
application with different login information the following error appears :
ExecuteReader requires an open and available Connection. The connection's
current state is closed.

I am NOT explicitly opening or closing the database connection whe creating
the context object. I am using the "Using context/End Using" configuration
when I am accessing the entities.

Here is how I am setting up my EntityConnection string

Dim sqlBuilder As SqlConnectionStringBuilder = New
SqlConnectionStringBuilder()
sqlBuilder.DataSource = "VN-DATASOURCE"
sqlBuilder.InitialCatalog = "InitCatalog"
sqlBuilder.MultipleActiveResultSets = True
sqlBuilder.Password = "password"
sqlBuilder.UserID = "userID"
Dim entBuilder As EntityConnectionStringBuilder = New
EntityConnectionStringBuilder()
entBuilder.Provider = "System.Data.SqlClient"
entBuilder.Metadata = "res://*/QEM.csdl|res://*/QEM.ssdl|res://*/QEM.msl"
entBuilder.ProviderConnectionString = sqlBuilder.ToString()

I have this nagging feeling that I am forgetting some IIS or Entity
Framework setting. Any help would be appreciated.
 
S

sqlguru

Entity Model framework, Linq, MVC framework, OR/M are all "hacks" in
the .NET framework. .NET is trying to be a slow All-In-One-Printer.

Get a beginners level book on application architecture, design
patterns, and database design so you can stop writing 1-2-3-poof magic
applications that display "Server timeout" and "Application not
responding".
 
M

Miha Markic

It sounds like you are using the same context for both users and that's
wrong.
You should create the context right before the operation, use it and dispose
it asap - don't hold it in memory.
 
M

Miha Markic

SQLGuru, you are mixing apples and motorcycles (what has MVC to do with
ORM?).
Then your perspective is wrong. ORMs are not hacks nor are slow. They are
tools that can be very powerfull in right hands. If you don't know how to
use them that's fine - don't use them, but don't assume they are
automatically bad just because of your ignorance.
And of course, your answer isn't helpful at all.
 
V

Vitoman

Thank you for your suggestion.

I had one static object creating an EntityConnection which would then be
used to create the context. I thought that a unique context would be
created based on the information from the EntityConnection object but
apparently it only allowed one context object to be created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top