2014-01-24 123 views
8

編輯:堆棧跟蹤添加在底部。如何讓Glimpse與EF6一起使用?

我有一個ASP.NET MVC 5項目,通過實體框架6.使用SQL Server數據庫

我加入掠影(和Glimpse.MVC5)的項目,並且工作正常。

但是,當我添加Glimpse.EF6時,我的應用程序一嘗試訪問數據庫就會引發異常。唯一的例外是:

System.NotSupportedException

無法確定類型的供應商工廠的供應商名稱 'System.Data.SqlClient.SqlClientFactory'。確保在應用程序配置中安裝或註冊了ADO.NET提供程序。

發生了什麼事?僅供參考,我的web.config的connectionStrings部分看起來是這樣的:

<connectionStrings> 
    <add name="DefaultConnection" connectionString="Data Source=.; Initial Catalog=foo; Integrated Security=True; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" /> 
</connectionStrings> 

...我Application_Start方法是這樣的:

protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas(); 
    GlobalConfiguration.Configure(WebApiConfig.Register); 
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
    RouteConfig.RegisterRoutes(RouteTable.Routes); 
    BundleConfig.RegisterBundles(BundleTable.Bundles); 

    Database.SetInitializer(new WebApplication.Models.Storage.ApplicationDbInitializer()); 
} 

...和我的上下文類看起來是這樣的:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
{ 
    public ApplicationDbContext() 
     : base("DefaultConnection") 
    { 
    } 

    public DbSet<Foo> Foos { get; set; } 
} 

在此先感謝您的幫助......


堆棧跟蹤:

[NotSupportedException: 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.Data.Entity.Utilities.DbProviderFactoryExtensions.GetProviderInvariantName(DbProviderFactory factory) +290 
System.Data.Entity.Infrastructure.DependencyResolution.DefaultInvariantNameResolver.GetService(Type type, Object key) +248 
System.Data.Entity.Infrastructure.DependencyResolution.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k) +75 
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72 
System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService(Type type, Object key) +210 
System.Data.Entity.Infrastructure.DependencyResolution.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r) +60 
System.Linq.WhereSelectArrayIterator`2.MoveNext() +66 
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +161 
System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key) +250 
System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService(Type type, Object key) +106 
System.Data.Entity.Infrastructure.DependencyResolution.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r) +60 
System.Linq.WhereSelectArrayIterator`2.MoveNext() +66 
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +94 
System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key) +250 
System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key) +102 
System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService(IDbDependencyResolver resolver, Object key) +145 
System.Data.Entity.Core.Common.<>c__DisplayClass5.<GetExecutionStrategy>b__4(ExecutionStrategyKey k) +84 
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72 
System.Data.Entity.Core.Common.DbProviderServices.GetExecutionStrategy(DbConnection connection, DbProviderFactory providerFactory) +351 
System.Data.Entity.Core.Common.DbProviderServices.GetExecutionStrategy(DbConnection connection) +62 
System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act) +319 
System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +335 
System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection) +399 
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +132 

[ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.] 
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +327 
Glimpse.EF.AlternateType.GlimpseDbProviderServices.GetDbProviderManifestToken(DbConnection connection) +113 
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +255 
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +67 

[ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.] 
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +277 
System.Data.Entity.Infrastructure.<>c__DisplayClass1.<ResolveManifestToken>b__0(Tuple`3 k) +63 
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72 
System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) +360 
System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +89 
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +79 
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +143 
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +171 
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +594 
System.Data.Entity.Internal.InternalContext.Initialize() +31 
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +39 
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +138 
System.Data.Entity.Internal.Linq.InternalSet`1.Include(String path) +41 
System.Data.Entity.Infrastructure.DbQuery`1.Include(String path) +142 
System.Data.Entity.QueryableExtensions.Include(IQueryable`1 source, String path) +205 
System.Data.Entity.QueryableExtensions.Include(IQueryable`1 source, Expression`1 path) +305 
Microsoft.AspNet.Identity.EntityFramework.UserStore`6.GetUserAggregateAsync(Expression`1 filter) +610 
Microsoft.AspNet.Identity.EntityFramework.UserStore`6.FindByNameAsync(String userName) +1070 
Microsoft.AspNet.Identity.<FindByNameAsync>d__10.MoveNext() +283 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 
System.Runtime.CompilerServices.ConfiguredTaskAwaiter.GetResult() +24 
Microsoft.AspNet.Identity.<FindAsync>d__18.MoveNext() +673 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24 
WebApplication.Controllers.<Login>d__2.MoveNext() in c:\Users\Gary\Documents\Visual Studio 2013\Projects\eByGum\WebApplication\Controllers\AccountController.cs:49 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 
System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 
System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +61 
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114 
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +66 
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102 
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49 
Castle.Proxies.AsyncControllerActionInvokerProxy.EndInvokeActionMethod_callback(IAsyncResult asyncResult) +42 
Castle.Proxies.Invocations.AsyncControllerActionInvoker_EndInvokeActionMethod.InvokeMethodOnTarget() +103 
Castle.DynamicProxy.AbstractInvocation.Proceed() +117 
Glimpse.Core.Extensibility.CastleInvocationToAlternateMethodContextAdapter.Proceed() +48 
Glimpse.Mvc.AlternateType.EndInvokeActionMethod.NewImplementation(IAlternateMethodContext context) +152 
Glimpse.Core.Extensibility.AlternateTypeToCastleInterceptorAdapter.Intercept(IInvocation invocation) +183 
Castle.DynamicProxy.AbstractInvocation.Proceed() +483 
Castle.Proxies.AsyncControllerActionInvokerProxy.EndInvokeActionMethod(IAsyncResult asyncResult) +203 
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +117 
System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +323 
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44 
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102 
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50 
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72 
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +184 
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40 
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34 
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44 
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39 
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39 
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39 
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39 
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40 
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38 
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514812 
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 
+0

您可以添加堆棧跟蹤嗎?或者甚至更好,在[我們的問題跟蹤器](https://github.com/glimpse/glimpse/issues)上創建問題,因爲這聽起來不像你做錯了什麼。就像快速檢查一樣,當您將Database.SetInitializer置於註釋中時,是否也有相同的問題? – cgijbels

+0

@cgijbels:刪除Database.SetInitializer沒有區別。我將添加堆棧跟蹤並創建一個問題。 –

+0

@cgijbels:添加爲[issue 173](https://github.com/Glimpse/Glimpse/issues/713)。謝謝。 –

回答

7

對於那些尋找一個解決辦法:

它看起來就像是一個bug within EF itself(它被提及爲173以上,但鏈接是正確的)。您可以等待EF 6.1.1/6.2,或者您可以降級到EF 6.0.2,並且它將重新開始工作。

在Package Manager控制檯,輸入:

Install-Package EntityFramework -Version 6.0.2 

,你應該是好去。

但只有當EF 6.0.2是您的選擇。祝你好運。

+1

回滾到6.0.2無助於那些使用Identity 2.0的人 – ScottE

+0

正確 - 感謝您指出@ScottE。希望EF的下一個版本能夠快速出來並解決此問題。 – PRB

+0

我已經回滾到6.0.2,仍然有一個問題.. 有沒有人得到它排序? –

0

嘗試添加以下到您的配置文件

<configuration> 
    <configSections>  
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 
+0

我已經有了類似的東西(我沒有顯示整個web.config文件 - 只有'connectionStrings'元素),但有趣的是我的'defaultConnectionFactory'被設置爲本地數據庫提供者。無論如何,我改變它與你的建議相同,不幸的是它沒有什麼區別 - 我仍然得到同樣的錯誤。 –

+0

另外,我應該補充,當我刪除Glimpse.EF6時,我所有的數據庫訪問都可以正常工作。這似乎是當我添加Glimpse.EF6時,它一切都出錯了。 –

+1

哇,安裝Glimpse.EF6似乎已經永久隱藏了我的項目,即使完全卸載Glimpse後,我也無法擺脫此錯誤。我被迫從備份恢復整個項目! –

相關問題