Helpful tip

Nov 18, 2010 at 1:51 PM
Edited Nov 18, 2010 at 1:51 PM

private SqlDataReader GetSqlReader(SqlCommand cmd)
{
    PortalContext pContext = PortalApplication.GetContext();
    Type tContext = pContext.GetType();
    PropertyInfo pSqlSession = tContext.GetProperty("AnalyticsSqlSession",
                 BindingFlags.NonPublic | BindingFlags.Instance);
    object sqlSession = pSqlSession.GetValue(pContext, null);

    Type tSqlSession = sqlSession.GetType();
    MethodInfo mExecute = tSqlSession.GetMethod("ExecuteReader",
                          new Type[1] { typeof(SqlCommand) });
    return mExecute.Invoke(sqlSession, new object[1] { cmd }) as SqlDataReader;
}

Thanks,

Michael Sullivan

Author of "Most Viewed Web Part" http://www.codeproject.com/KB/sharepoint/SPMostViewedWebPart.aspx