2014-07-16 88 views
0

我的程序中有一個非常奇怪的錯誤我正在使用實體框架(代碼優先),每當我運行我的程序並首次訪問我的DbContext時我得到ProviderIncompatibleException ,但是如果我退出程序並再次運行它,一切工作正常。完全的例外是:實體框架 - ProviderIncompatibleException只有第一次運行我的程序

System.Data.Entity.Core.ProviderIncompatibleException was unhandled 
    HResult=-2146233087 
    Message=An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. 
    Source=EntityFramework 
    StackTrace: 
     at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) 
     at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) 
     at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) 
     at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) 
     at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) 
     at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) 
     at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 
     at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) 
     at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() 
     at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() 
     at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
     at IEX.ManagementServer.Monitor.IMSMonitor.MonitoringManager.Start() in C:\Develop\IEX\trunk\IEX.ManagementServer\IEX.ManagementServer.Monitor\IMSMonitor\MonitoringManager.cs:line 209 
     at IEX.ManagementServer.WebServices.Host.Mediator.Initialize(Boolean dropAlways) in C:\Develop\IEX\trunk\IEX.ManagementServer\IEX.ManagementServer.WebServices.Host\Mediator.cs:line 49 
     at IEX.ManagementServer.WebServices.Host.Program.Main(String[] args) in C:\Develop\IEX\trunk\IEX.ManagementServer\IEX.ManagementServer.WebServices.Host\Program.cs:line 51 
    InnerException: System.Data.Entity.Core.ProviderIncompatibleException 
     HResult=-2146233087 
     Message=The provider did not return a ProviderManifestToken string. 
     Source=EntityFramework 
     StackTrace: 
      at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) 
      at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) 
     InnerException: System.Data.SqlClient.SqlException 
      HResult=-2146232060 
      Message=A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 
      Source=.Net SqlClient Data Provider 
      ErrorCode=-2146232060 
      Class=20 
      LineNumber=0 
      Number=-1 
      Server="" 
      State=0 
      StackTrace: 
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 
       at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) 
       at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) 
       at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) 
       at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) 
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) 
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) 
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) 
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) 
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) 
       at System.Data.SqlClient.SqlConnection.Open() 
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0() 
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation) 
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act) 
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) 
       at System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection) 
       at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) 
      InnerException: 

有人請幫忙嗎?

+0

你是什麼意思第一次?你開始編程,關閉它,然後重新開始?當再次發生錯誤? –

+0

當我第一次啓動時...開始 - >錯誤發生,停止,開始 - >一切正常... –

+0

感興趣的錯誤是:HResult = -2146232060 消息=網絡相關或特定實例在建立與SQL Server的連接時發生錯誤。服務器未找到或無法訪問。驗證實例名稱是否正確,並將SQL Server配置爲允許遠程連接。 (提供程序:SQL網絡接口,錯誤:26 - 指定錯誤定位服務器/實例) – ErikEJ

回答

0

我知道這是一個古老的線程。但是,無論如何,你是否試圖在運行時更改app.config文件?

它發生在我身上,@Evk給了我一個great explanation發生了什麼事。

相關問題