Using mvc-mini-profiler with ADO.NET SqlConnection

I am trying to use (awesome) mvc-mini-profiler with some pre-existing SqlConnection stored procedure code (we do not use EF or L2S, but only ADO.NET for SQL Server 2008). I am looking for some guidelines for integrating inherited types ProfiledDbinto this type of code.

var con = new SqlConnection("connectionstring");  
var cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.CommandText = "SP_STORED_PROCEDURE_NAME";
cmd.Paramters.Add("recordsetid",SqlDbType.UniqueIdentifier).Value = recordsetid;
var dSet = new DataSet();
var da = new SqlDataAdapter(cmd);
da.fill(dSet);
<parse DataSet>

Any help here for us obsolete ADO.NET users would be great, because at first glance it seems that the SQL profiler should be applicable to this situation.

+5
source share
2 answers

You will need to complete the connection and use the DbConnection CreateCommandfactory.

pass , SqlParameter, .

:

var cnn = MvcMiniProfiler.Data.ProfiledDbConnection.Get(new SqlConnection(str));
var cmd = cnn.CreateCommand();
var param = cmd.CreateParameter(); 
...

DataSets DataAdapters, , Dapper , . , Google.

+4

, SQL , ADO.NET, . , , MiniProfiler.

, , , , MiniProfiler.Step() . , ExecuteReader() et al , , SqlCommands , , :

protected SqlDataReader ExecuteReader()
{
    SqlDataReader reader = null;

    // sqlComm is a member of a base class which this method is part of. I also 
    // happen to know that sqlComm.CommandText will always refer to a stored
    // procedure name so it makes it easy to view in the results.
    using (MiniProfiler.Current.Step(sqlComm.CommandText))
    {
        try
        {
            sqlConn.Open();
            reader = sqlComm.ExecuteReader();
        }
        catch (SqlException exception)
        {
            sqlConn.Close();
            // Error handling removed for brevity...
        } 
    }

    return reader;
}

, , , , , , .

+3

All Articles