1. 程式人生 > 其它 >【異常處理】無法將型別為“Glimpse.Ado.AlternateType.GlimpseDbConnection”的物件強制轉換為型別“System.Data.SqlClient.SqlConnection”。

【異常處理】無法將型別為“Glimpse.Ado.AlternateType.GlimpseDbConnection”的物件強制轉換為型別“System.Data.SqlClient.SqlConnection”。

最近在整合EF到現有系統中,呼叫ToList的時候就會報這個錯誤

Unable to determine the provider name for provider factory of type 'System.Data.SqlClient.SqlClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.

堆疊如下

System.InvalidCastException: 無法將型別為“Glimpse.Ado.AlternateType.GlimpseDbConnection”的物件強制轉換為型別“System.Data.SqlClient.SqlConnection”。 
在 System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
在 System.Data.Entity.Core.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand, EntityTransaction entityTransaction, DbCommand storeProviderCommand)
在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.PrepareEntityCommandBeforeExecution(EntityCommand entityCommand)
在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
在 System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1
func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.b__9()
在 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
在 System.Data.Entity.Core.Objects.ObjectQuery`1
.GetResults(Nullable`1 forMergeOption)
在 System.Data.Entity.Core.Objects.ObjectQuery`1..GetEnumerator>b__0()
在 System.Lazy`1.CreateValue()
在 System.Lazy`1.LazyInitValue()
在 System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
在 System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
在 System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey)
在 System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey)
在 System.Data.Entity.Migrations.History.HistoryRepository.GetLastModel(String& migrationId, String contextKey)
在 System.Data.Entity.Migrations.History.HistoryRepository.GetLastModel()
在 System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata)
在 System.Data.Entity.CreateDatabaseIfNotExists`1
.InitializeDatabase(TContext context)
在 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
在 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
在 System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
在 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
在 System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
在 System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
在 System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
在 System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
在 UFSoft.UBF.MVC.MainController.TestEF(String uid)
位置 G:\yonyou\U9CE\UBF\UBF\ADF\UI\UI_MVC\Controller\MainController.cs:行號 3402
每天進步一丟丟
防盜簽名:本文來自【部落格園】-【多安分】

恭喜兄dei,看到這個隱藏標籤~~~如果覺得部落格內容有所幫助,請掃二維碼打賞,感謝老鐵

支付寶

微信