Sometimes, not always, I'm getting following error: "The underlying provider failed on open."
This is my situation:
I have a list of integer keys I process in parallel to be used as parameter in a compiled select query. I use this in a RIA domainservice.
var queryResult = new List<int> {1, 2, 3}.AsParallel().Select(i => CompiledQueries.GetRecordByKey(this.ObjectContext, i)).ToList();
This is how the compiled query looks like:
public static IEnumerable<CompiledQueryResult> GetRecordByKey(MyEntities _context, int _key)
{
if (_getRecordByKey == null)
{
_getRecordByKey = CompiledQuery.Compile<MyEntities, int, IEnumerable<CompiledQueryResult>>
((ctx, key) =>
ctx.Records
.Where(r => r.Id == key)
.Select(r => new CompiledQueryResult
{
Id = r.ID,
Name = r.Name,
...
})
);
}
return _getRecordByKey.Invoke(_context, _key);
}
I'm using EF4, RIA (Actually the ObjectContext of the domainservice is passed to the compiled query method), the connection string contains the famous MultipleActiveResultSets=True... When MultipleActiveResultSets is set to false I get the error immediately.
The code used here is a simplified version of the real code. I'm also passing a lot more keys, thus more parallel queries..
Sometimes I see in the inner exception that a data reader is being closed, but the status is connecting..
I've tried to enlarge the connection pool size, but without succes.
Has anyone good suggestions to resolve this problem? Thx in advance.