C/C++教程

【异常处理】无法将类型为“Glimpse.Ado.AlternateType.GlimpseDbConnection”的对象强制转换为类型“System.Data.SqlClient.SqlConne

本文主要是介绍【异常处理】无法将类型为“Glimpse.Ado.AlternateType.GlimpseDbConnection”的对象强制转换为类型“System.Data.SqlClient.SqlConne,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

最近在集成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

 

这篇关于【异常处理】无法将类型为“Glimpse.Ado.AlternateType.GlimpseDbConnection”的对象强制转换为类型“System.Data.SqlClient.SqlConne的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!