在 Mini Profiler 文档中,您可以执行以下操作:
public static DbConnection GetOpenConnection()
{
var cnn = CreateRealConnection(); // A SqlConnection, SqliteConnection ... or whatever
// wrap the connection with a profiling connection that tracks timings
return new StackExchange.Profiling.Data.ProfiledDbConnection(cnn, MiniProfiler.Current);
}
如何在我自己的数据库连接上使用 Miniprofiler 实现的 Servicestack 版本在 Servicestack 中启用已分析的数据库连接。我有一个返回连接字符串的函数,而不是使用 servicestack 内置的 base.Db。
public static DbConnection GetOpenConnection(string ConnectionName)
{
string provider = ConfigurationManager.ConnectionStrings[ConnectionName].ProviderName;
string connectionstring = ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString;
DbProviderFactory factory = DbProviderFactories.GetFactory(provider);
DbConnection cnn = factory.CreateConnection();
cnn.ConnectionString = connectionstring;
cnn.Open();
//this is ServiceStack current profiler for request and response DTO's
Profiler profiler = Profiler.Current;
// I want to return a profiled db connection here that will include the connection profiles into the current Profiler data.
return cnn;
}