First a disclaimer - I did my research on the topic and found plenty of material. Sadly, none of that was to any help, as each answer can be counted into the following categories.
- Permission issues for accessing database
- Miscellaneous missconfigurations
- Incorrect garbage disposal
- Application of MultipleActiveResultSets
- Usage of ToList() indiscriminately
My issue occurs only when fetching/executing larger sets, so we can eliminate (1) and (2). Since I can execute a number of queries in the same context getting the exception on fourth or fifth reading, we can eliminate (3). I've checked the connection string and (4) can't be the problem because the multiplicity is already enabled. The last candidate is (5) but it can be eliminated as well, because I'm getting the same issues when wsitching to IEnumerable.
My impression is that the server somehow times out because the current operation takes too long time. I can either fetch my list entirely without filtration for filtration in the client (which takes a slight forever and fails due to that) or I can apply Where (which requires to use Contains versus another list, which is equivalent to IN in SQL'ish and fails due to that).
I'm kind of at the point when banging my head into a wall slowly emerges as a reasonable approach. I have no control over the DB schema nor ISS (so this kind of hints can't even be tested). I have some influence on the configuration of the EF but due to ignorance and outmost respect to the things I don't fully master, I'm very cautious. What can be done here?
The config file looks as follows.
app.config(50,191):
<add name="ModelContainer"
connectionString="metadata=res://*/Model.csdl
|res://*/Model.ssdl
|res://*/Model.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=1.2.3.4;
initial catalog=DataBaseName;
user id=NServiceBus;
password=Abc123();
MultipleActiveResultSets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
C# (when I switch the execution order, the failure happens on the second line - beep or boop, whichever comes first does succeed).
List<Beep> beeps = context.Beeps.ToList();
List<Boop> boops = context.Boops.ToList();