我正在使用ASP.Net MVC 3和Entity Framework代码优先构建的项目中使用mvc-mini-profiler.
一切都很有效,直到我尝试通过ProfiledDbConnection在文档中描述的方式包装连接来添加数据库分析.由于我使用的是DbContext,因此我尝试提供连接的方式是使用静态工厂方法构造函数:
public class MyDbContext : DbContext
{
public MyDbContext() : base(GetProfilerConnection(), true)
{ }
private static DbConnection GetProfilerConnection()
{
// Code below errors
//return ProfiledDbConnection.Get(new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionName"].ConnectionString));
// Code below works fine...
return new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionName"].ConnectionString);
}
//...
}
Run Code Online (Sandbox Code Playgroud)
使用时ProfiledDbConnection,我收到以下错误:
ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.
堆栈跟踪:
[ArgumentException: The connection is not of type 'System.Data.SqlClient.SqlConnection'.]
System.Data.SqlClient.SqlProviderUtilities.GetRequiredSqlConnection(DbConnection connection) +10486148
System.Data.SqlClient.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection) +77
System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +44
[ProviderIncompatibleException: The provider did not …Run Code Online (Sandbox Code Playgroud)