2

後與MiniProfiler努力使分析的數據庫查詢小時後返回空,我有沒有運氣,我得到的錯誤:MiniProfiler設置 - 調用「get_ProviderFactory」的方法

A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'StackExchange.Profiling.Data.ProfiledDbConnection'. The store provider might not be functioning correctly.

我通過了許多SO帖子,但迄今爲止沒有任何工作,如this後,這是大約相同的錯誤,但具有不同的配置,以及沒有答案。現在我知道ProfiledDbConnection不是重寫DbProviderFactory,它的父類DbConnection在它的DbProviderFactory的實現中返回null,所以錯誤是可以預料的,但它應該以某種方式工作。有一個MiniProfilerEF.Initialize(),但它的接縫只能用於CodeFirst,而我正在使用DatabaseFirst方法。

我已經安裝了MiniProfiler,MiniProfiler.EF,MiniProfilerMVC3 nuget軟件包。這裏是我的代碼:

 string connectionString = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString; 
     var sqlConnection = new SqlConnection(connectionString); 
     var profiled = new ProfiledDbConnection(sqlConnection, MiniProfiler.Current); 
     var db = new DbContext(profiled, true); 
     db.Set<Customer>().ToList(); 

而且我使用asp.net mvc4,EF5,DatabseFirst,MiniProfiler 2.1.0.0時,SQL Server

任何想法?

回答

2

因此,來自您的評論所以,來自您對Setup of mvc-mini-profiler for EF-db- first的評論,您是否嘗試刪除Mini Profiler特定的包裝?

var profiled = new ProfiledDbConnection(sqlConnection, MiniProfiler.Current); 
var db = new DbContext(profiled, true); 
db.Set<Customer>().ToList(); 

相反,只是增加

protected void Application_Start() 
{ 
    // any other code 
    MiniProfilerEF.Initialize(); 
} 

,然後做標準DB訪問?

using (var db = new WordsEntities()) { 
    var posts = db.Customer.Take(4); 
    // more code 
} 
+0

這是我沒有嘗試過的,現在它工作正常,非常感謝。我應該更深入地調查初始化方法,並避免對該行的誤導性評論:'// TODO:如果您正在分析EF代碼,請首先嚐試: //MiniProfilerEF.Initialize();' – VahidNaderi

+0

很高興幫助/工作! –

相關問題