Currently working with codefirst v5 on .net 4.5
I have 1 'master' context which includes a locations table called 'Geonames' (snippet below)
public class CoreContext : DbContext
: base("Conn")
{
public DbSet<GeoName> GeoNames { get; set; }
}
The reference here is simply to be able to manage migrations on the table.
Site will have the ability to 'plug-in' different location providers and the geonames table is there to provide a local provider implementation. The provider is set in the configuration of the website simply setting the classname and namespace of the actual implementation. It uses an interface like this (simplified)
public interface ILocationProvider
{
IEnumerable<Location> LocationsByName(String Name);
}
The concrete implementation is instantiated as below (simplified)
public static ILocationProvider GetLocationProvider()
{
ILocationProvider Provider = null;
Provider = Activator.CreateInstance(Type.GetType("{selected namespace.classname}")) as ILocationProvider;
}
catch (Exception ex)
{
throw ex;
}
if (Provider == null)
{
throw new NullReferenceException("Could not create an instance of the location Provider");
}
return Provider;
}
The concrete implementation is as follows(simplified)
public class LocalLocationProvider : ILocationProvider
{
public IEnumerable<Location> LocationsByName(string Name)
{
List<Location> locations = new List<Location>();
using (var db = new LocalLocationContext())
{
foreach (var item in db.GeoNames.Where(X => X.Name.Contains(Name)))
{
locations.Add(
new Location { Id = item.Id, Name = item.Name, GeoLocation = item.GeoLocation }
);
}
}
return locations;
}
private class LocalLocationContext : DbContext
{
public LocalLocationContext()
: base("Conn")
{
Database.SetInitializer<LocalLocationContext>(null);
}
public DbSet<GeoName> GeoNames { get; set; }
}
}
The concrete implementation instantiates just fine and I call the method 'LocationsByName' .. but here the trouble starts. When the code line below executes
foreach (var item in db.GeoNames.Where(X => X.Name.Contains(Name)))
{
..
}
I get the following error.
Exception Details: System.ComponentModel.Win32Exception: The wait operation timed out
[Win32Exception (0x80004005): The wait operation timed out]
[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1753986
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5296058
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +59
System.Data.SqlClient.SqlDataReader.get_MetaData() +90
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +365
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +1379
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +175
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +134
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +437
I have tried to instantiate 'LocalLocationContext' without using the 'Activator.CreateInstance()' method I can query the data just fine.
To me it seems obvious that it has got something to do with how I get my actual implemention of the location provider just can't spot what the error or issue is.
Thanks in advance.