3

現在、.net4.5でcodefirstv5を使用しています

'Geonames'という場所テーブルを含む1つの'master'コンテキストがあります(以下のスニペット)

public class CoreContext : DbContext
            : base("Conn")
{
    public DbSet<GeoName> GeoNames { get; set; }
}

ここでの参照は、単にテーブル上の移行を管理できるようにすることです。

サイトにはさまざまなロケーションプロバイダーを「プラグイン」する機能があり、geonamesテーブルはローカルプロバイダーの実装を提供するためにあります。プロバイダーは、実際の実装のクラス名と名前空間を設定するだけで、Webサイトの構成に設定されます。このようなインターフェースを使用します(簡略化)

public interface ILocationProvider
{
    IEnumerable<Location> LocationsByName(String Name);
}    

具体的な実装は以下のようにインスタンス化されます(簡略化)

    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;
    }

具体的な実装は以下のとおりです(簡略化)

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; }
    }
}

具体的な実装は問題なくインスタンス化され、メソッド'LocationsByName' ..を呼び出しますが、ここで問題が発生します。以下のコード行が実行されるとき

foreach (var item in db.GeoNames.Where(X => X.Name.Contains(Name)))
{
  ..
}

次のエラーが発生します。

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

'Activator.CreateInstance()'メソッドを使用せずに'LocalLocationContext'をインスタンス化しようとしましたが、データを正常にクエリできます。

私には、ロケーションプロバイダーの実際の実装を取得する方法と関係があることは明らかであるように思われますが、エラーや問題が何であるかを特定することはできません。

前もって感謝します。

4

0 に答える 0