private PersonalizationStateInfoCollection FindUserState(string path,
                                                                 DateTime inactiveSinceDate,
                                                                 string username,
                                                                 int pageIndex,
                                                                 int pageSize,
                                                                 out int totalRecords)
        {
            const string findUserState =
                "SELECT Paths.Path, PerUser.LastUpdatedDate, LEN(PerUser.PageSettings), Users.UserName, Users.LastActivityDate" +
                " FROM aspnet_PagePersonalizationPerUser PerUser, aspnet_Users Users, aspnet_Paths Paths" +
                " WHERE PerUser.UserId = Users.UserId AND PerUser.PathId = Paths.PathId" +
                " AND Paths.ApplicationId = @ApplicationId";
            const string orderBy = " ORDER BY Paths.Path ASC, Users.UserName ASC";

            AccessConnectionHolder connectionHolder = null;
            OleDbConnection connection = null;
            OleDbDataReader reader = null;
            totalRecords = 0;

            try
            {
                try
                {
                    OleDbParameter parameter;
                    connectionHolder = GetConnectionHolder();
                    connection = connectionHolder.Connection;
                    OleDbCommand command = new OleDbCommand();
                    command.Connection = connection;
                    OleDbParameterCollection parameters = command.Parameters;

                    int appId = GetApplicationID(connectionHolder);
                    parameters.AddWithValue("ApplicationId", appId);

                    command.CommandText = findUserState;
                    if (inactiveSinceDate != DateTime.MinValue)
                    {
                        command.CommandText += " AND Users.LastActivityDate <= @InactiveSinceDate";

                        // Note: OleDb provider does not handle datetime that has non-
                        // zero millisecond, so it needs to be rounded up.
                        parameter = parameters.Add("InactiveSinceDate", OleDbType.DBTimeStamp);
                        parameter.Value = new DateTime(inactiveSinceDate.Year, inactiveSinceDate.Month, inactiveSinceDate.Day,
                                                       inactiveSinceDate.Hour, inactiveSinceDate.Minute, inactiveSinceDate.Second);
                    }

                    if (path != null)
                    {
                        command.CommandText += " AND Paths.Path LIKE @Path";
                        parameter = parameters.Add("Path", OleDbType.WChar);
                        parameter.Value = path;
                    }

                    if (username != null)
                    {
                        command.CommandText += " AND Users.UserName LIKE @UserName";
                        parameter = parameters.Add("UserName", OleDbType.WChar);
                        parameter.Value = username;
                    }

                    command.CommandText += orderBy;
                    reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                    PersonalizationStateInfoCollection stateInfoCollection = new PersonalizationStateInfoCollection();
                    long recordCount = 0;
                    long lBound = pageIndex * pageSize;
                    long uBound = lBound + pageSize;

                    while (reader.Read())
                    {
                        recordCount++;
                        if (recordCount <= lBound || recordCount > uBound)
                        {
                            continue;
                        }

                        string returnedPath = reader.GetString(0);
                        DateTime lastUpdatedDate = reader.GetDateTime(1);
                        int size = reader.GetInt32(2);
                        string returnedUsername = reader.GetString(3);
                        DateTime lastActivityDate = reader.GetDateTime(4);
                        stateInfoCollection.Add(new UserPersonalizationStateInfo(
                                                        returnedPath, lastUpdatedDate,
                                                        size, returnedUsername, lastActivityDate));
                    }
                    totalRecords = (int)recordCount;
                    return stateInfoCollection;
                }
                finally
                {
                    if (connectionHolder != null)
                    {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }

                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
            }
            catch
            {
                throw;
            }
        }
        private PersonalizationStateInfoCollection FindSharedState(string path,
                                                                   int pageIndex,
                                                                   int pageSize,
                                                                   out int totalRecords) {
            SqlConnectionHolder connectionHolder = null;
            SqlConnection connection = null;
            SqlDataReader reader = null;
            totalRecords = 0;

            // Extra try-catch block to prevent elevation of privilege attack via exception filter
            try {
                try {
                    connectionHolder = GetConnectionHolder();
                    connection = connectionHolder.Connection;
                    Debug.Assert(connection != null);

                    CheckSchemaVersion( connection );

                    SqlCommand command = new SqlCommand("dbo.aspnet_PersonalizationAdministration_FindState", connection);
                    SetCommandTypeAndTimeout(command);
                    SqlParameterCollection parameters = command.Parameters;

                    SqlParameter parameter = parameters.Add(new SqlParameter("AllUsersScope", SqlDbType.Bit));
                    parameter.Value = true;

                    parameters.AddWithValue("ApplicationName", ApplicationName);
                    parameters.AddWithValue("PageIndex", pageIndex);
                    parameters.AddWithValue("PageSize", pageSize);

                    SqlParameter returnValue = new SqlParameter("@ReturnValue", SqlDbType.Int);
                    returnValue.Direction = ParameterDirection.ReturnValue;
                    parameters.Add(returnValue);

                    parameter = parameters.Add("Path", SqlDbType.NVarChar);
                    if (path != null) {
                        parameter.Value = path;
                    }

                    parameter = parameters.Add("UserName", SqlDbType.NVarChar);
                    parameter = parameters.Add("InactiveSinceDate", SqlDbType.DateTime);

                    reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                    PersonalizationStateInfoCollection sharedStateInfoCollection = new PersonalizationStateInfoCollection();

                    if (reader != null) {
                        if (reader.HasRows) {
                            while(reader.Read()) {
                                string returnedPath = reader.GetString(0);

                                // Data can be null if there is no data associated with the path
                                DateTime lastUpdatedDate = (reader.IsDBNull(1)) ? DateTime.MinValue :
                                                                DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
                                int size = (reader.IsDBNull(2)) ? 0 : reader.GetInt32(2);
                                int userDataSize = (reader.IsDBNull(3)) ? 0 : reader.GetInt32(3);
                                int userCount = (reader.IsDBNull(4)) ? 0 : reader.GetInt32(4);
                                sharedStateInfoCollection.Add(new SharedPersonalizationStateInfo(
                                    returnedPath, lastUpdatedDate, size, userDataSize, userCount));
                            }
                        }

                        // The reader needs to be closed so return value can be accessed
                        // See MSDN doc for SqlParameter.Direction for details.
                        reader.Close();
                        reader = null;
                    }

                    // Set the total count at the end after all operations pass
                    if (returnValue.Value != null && returnValue.Value is int) {
                        totalRecords = (int)returnValue.Value;
                    }

                    return sharedStateInfoCollection;
                }
                finally {
                    if (reader != null) {
                        reader.Close();
                    }

                    if (connectionHolder != null) {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch {
                throw;
            }
        }
Example #3
0
        private PersonalizationStateInfoCollection FindSharedState(string path,
                                                                   int pageIndex,
                                                                   int pageSize,
                                                                   out int totalRecords)
        {
            SqlConnectionHolder connectionHolder = null;
            SqlConnection       connection       = null;
            SqlDataReader       reader           = null;

            totalRecords = 0;

            // Extra try-catch block to prevent elevation of privilege attack via exception filter
            try {
                try {
                    connectionHolder = GetConnectionHolder();
                    connection       = connectionHolder.Connection;
                    Debug.Assert(connection != null);

                    CheckSchemaVersion(connection);

                    SqlCommand command = new SqlCommand("dbo.aspnet_PersonalizationAdministration_FindState", connection);
                    SetCommandTypeAndTimeout(command);
                    SqlParameterCollection parameters = command.Parameters;

                    SqlParameter parameter = parameters.Add(new SqlParameter("AllUsersScope", SqlDbType.Bit));
                    parameter.Value = true;

                    parameters.AddWithValue("ApplicationName", ApplicationName);
                    parameters.AddWithValue("PageIndex", pageIndex);
                    parameters.AddWithValue("PageSize", pageSize);

                    SqlParameter returnValue = new SqlParameter("@ReturnValue", SqlDbType.Int);
                    returnValue.Direction = ParameterDirection.ReturnValue;
                    parameters.Add(returnValue);

                    parameter = parameters.Add("Path", SqlDbType.NVarChar);
                    if (path != null)
                    {
                        parameter.Value = path;
                    }

                    parameter = parameters.Add("UserName", SqlDbType.NVarChar);
                    parameter = parameters.Add("InactiveSinceDate", SqlDbType.DateTime);

                    reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                    PersonalizationStateInfoCollection sharedStateInfoCollection = new PersonalizationStateInfoCollection();

                    if (reader != null)
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                string returnedPath = reader.GetString(0);

                                // Data can be null if there is no data associated with the path
                                DateTime lastUpdatedDate = (reader.IsDBNull(1)) ? DateTime.MinValue :
                                                           DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
                                int size         = (reader.IsDBNull(2)) ? 0 : reader.GetInt32(2);
                                int userDataSize = (reader.IsDBNull(3)) ? 0 : reader.GetInt32(3);
                                int userCount    = (reader.IsDBNull(4)) ? 0 : reader.GetInt32(4);
                                sharedStateInfoCollection.Add(new SharedPersonalizationStateInfo(
                                                                  returnedPath, lastUpdatedDate, size, userDataSize, userCount));
                            }
                        }

                        // The reader needs to be closed so return value can be accessed
                        // See MSDN doc for SqlParameter.Direction for details.
                        reader.Close();
                        reader = null;
                    }

                    // Set the total count at the end after all operations pass
                    if (returnValue.Value != null && returnValue.Value is int)
                    {
                        totalRecords = (int)returnValue.Value;
                    }

                    return(sharedStateInfoCollection);
                }
                finally {
                    if (reader != null)
                    {
                        reader.Close();
                    }

                    if (connectionHolder != null)
                    {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch {
                throw;
            }
        }
        private PersonalizationStateInfoCollection FindSharedState(string path,
                                                                   int pageIndex,
                                                                   int pageSize,
                                                                   out int totalRecords)
        {
            const string findSharedState =
                "SELECT Paths.Path, AllUsers.LastUpdatedDate, LEN(AllUsers.PageSettings)" +
                " FROM aspnet_PagePersonalizationAllUsers AllUsers, aspnet_Paths Paths" +
                " WHERE AllUsers.PathId = Paths.PathId AND Paths.ApplicationId = @ApplicationId";
            const string orderBy = " ORDER BY Paths.Path ASC";
            const string findUserState =
                "SELECT SUM(LEN(PerUser.PageSettings)), COUNT(*)" +
                " FROM aspnet_PagePersonalizationPerUser PerUser, aspnet_Paths Paths" +
                " WHERE PerUser.PathId = Paths.PathId" +
                " AND Paths.ApplicationId = @ApplicationId" +
                " AND Paths.Path LIKE @Path";

            AccessConnectionHolder connectionHolder = null;
            OleDbConnection connection = null;
            OleDbDataReader reader = null;
            totalRecords = 0;

            try
            {
                try
                {
                    connectionHolder = GetConnectionHolder();
                    connection = connectionHolder.Connection;
                    OleDbCommand command = new OleDbCommand(findSharedState, connection);
                    OleDbParameterCollection parameters = command.Parameters;
                    OleDbParameter parameter;

                    int appId = GetApplicationID(connectionHolder);
                    parameters.AddWithValue("ApplicationId", appId);

                    if (path != null)
                    {
                        command.CommandText += " AND Paths.Path LIKE @Path";
                        parameter = parameters.Add("Path", OleDbType.WChar);
                        parameter.Value = path;
                    }

                    command.CommandText += orderBy;
                    reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                    PersonalizationStateInfoCollection stateInfoCollection = new PersonalizationStateInfoCollection();
                    long recordCount = 0;
                    long lBound = pageIndex * pageSize;
                    long uBound = lBound + pageSize;

                    while (reader.Read())
                    {
                        recordCount++;
                        if (recordCount <= lBound || recordCount > uBound)
                        {
                            continue;
                        }

                        string returnedPath = reader.GetString(0);
                        DateTime lastUpdatedDate = reader.GetDateTime(1);
                        int size = reader.GetInt32(2);

                        // Create temp info since we need to retrieve the corresponding personalization size and count later
                        stateInfoCollection.Add(new SharedPersonalizationStateInfo(returnedPath, lastUpdatedDate, size, -1, -1));
                    }
                    totalRecords = (int)recordCount;

                    // We need to close the reader in order to make other queries
                    reader.Close();
                    command = new OleDbCommand(findUserState, connection);
                    parameters = command.Parameters;

                    parameters.AddWithValue("ApplicationId", appId);
                    parameter = parameters.Add("Path", OleDbType.WChar);
                    PersonalizationStateInfoCollection sharedStateInfoCollection = new PersonalizationStateInfoCollection();

                    foreach (PersonalizationStateInfo stateInfo in stateInfoCollection)
                    {
                        parameter.Value = stateInfo.Path;

                        reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                        reader.Read();
                        int sizeOfPersonalizations = Convert.ToInt32(reader.GetValue(0), CultureInfo.InvariantCulture);
                        int countOfPersonalizations = reader.GetInt32(1);
                        reader.Close();
                        sharedStateInfoCollection.Add(new SharedPersonalizationStateInfo(
                                                            stateInfo.Path, stateInfo.LastUpdatedDate,
                                                            stateInfo.Size, sizeOfPersonalizations, countOfPersonalizations));
                    }

                    return sharedStateInfoCollection;
                }
                finally
                {
                    if (connectionHolder != null)
                    {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }

                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
            }
            catch
            {
                throw;
            }
        }
    private PersonalizationStateInfoCollection FindUserState(string path, DateTime inactiveSinceDate, string userName, int pageIndex, int pageSize, out int totalRecords)
    {
      MySQLPersonalizationConnectionHelper connection = new MySQLPersonalizationConnectionHelper(connectionString);
      
      try
      {

        MySqlCommand cmd = new MySqlCommand();
        connection.OpenConnection(true);
        totalRecords = PersonalizationProviderProcedures.myaspnet_PersonalizationAdministration_FindState(false, ApplicationId, ApplicationName, pageIndex, pageSize, 
                       path, userName, inactiveSinceDate, connection, ref cmd);

        PersonalizationStateInfoCollection stateInfoCollection = new PersonalizationStateInfoCollection();

        using(var reader = cmd.ExecuteReader())
        {          
          while (reader.Read())
          {
            string pathQuery = reader.GetString("Path");
            DateTime lastUpdatedDate = DateTime.SpecifyKind(reader.GetDateTime("LastUpdatedDate"), DateTimeKind.Utc);
            int size = reader.GetInt32("Size");
            string usernameQuery = reader.GetString("name");
            DateTime lastActivityDate = DateTime.SpecifyKind(reader.GetDateTime("LastActivityDate"), DateTimeKind.Utc);
            stateInfoCollection.Add(new UserPersonalizationStateInfo(pathQuery, lastActivityDate, size, usernameQuery, lastActivityDate));        
          }
        }       
        connection.CloseConnection();        

        return stateInfoCollection;
      }
      catch (Exception ex)
      {
        if (writeExceptionsToEventLog)
          WriteToEventLog(ex, "MySQLPersonalizationProvider - FindUserState");        
        throw;
      }
      finally
      {
        connection.CloseConnection();
      }
    }  
Example #6
0
        private PersonalizationStateInfoCollection FindSharedState(string path, int pageIndex, int pageSize, out int totalRecords)
        {
            SqlConnectionHolder connectionHolder = null;
            SqlConnection       connection       = null;
            SqlDataReader       reader           = null;
            PersonalizationStateInfoCollection infos2;

            totalRecords = 0;
            try
            {
                try
                {
                    connectionHolder = this.GetConnectionHolder();
                    connection       = connectionHolder.Connection;
                    this.CheckSchemaVersion(connection);
                    SqlCommand command = new SqlCommand("dbo.aspnet_PersonalizationAdministration_FindState", connection);
                    this.SetCommandTypeAndTimeout(command);
                    SqlParameterCollection parameters = command.Parameters;
                    parameters.Add(new SqlParameter("AllUsersScope", SqlDbType.Bit)).Value = true;
                    parameters.AddWithValue("ApplicationName", this.ApplicationName);
                    parameters.AddWithValue("PageIndex", pageIndex);
                    parameters.AddWithValue("PageSize", pageSize);
                    SqlParameter parameter2 = new SqlParameter("@ReturnValue", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.ReturnValue
                    };
                    parameters.Add(parameter2);
                    SqlParameter parameter = parameters.Add("Path", SqlDbType.NVarChar);
                    if (path != null)
                    {
                        parameter.Value = path;
                    }
                    parameter = parameters.Add("UserName", SqlDbType.NVarChar);
                    parameter = parameters.Add("InactiveSinceDate", SqlDbType.DateTime);
                    reader    = command.ExecuteReader(CommandBehavior.SequentialAccess);
                    PersonalizationStateInfoCollection infos = new PersonalizationStateInfoCollection();
                    if (reader != null)
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                string   str                     = reader.GetString(0);
                                DateTime lastUpdatedDate         = reader.IsDBNull(1) ? DateTime.MinValue : DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
                                int      size                    = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                                int      sizeOfPersonalizations  = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                                int      countOfPersonalizations = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                                infos.Add(new SharedPersonalizationStateInfo(str, lastUpdatedDate, size, sizeOfPersonalizations, countOfPersonalizations));
                            }
                        }
                        reader.Close();
                        reader = null;
                    }
                    if ((parameter2.Value != null) && (parameter2.Value is int))
                    {
                        totalRecords = (int)parameter2.Value;
                    }
                    infos2 = infos;
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                    if (connectionHolder != null)
                    {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch
            {
                throw;
            }
            return(infos2);
        }
    private PersonalizationStateInfoCollection FindSharedState(string path, int pageIndex, int pageSize, out int totalRecords)
    {
      MySQLPersonalizationConnectionHelper connection = new MySQLPersonalizationConnectionHelper(connectionString);

      try
      {
        MySqlCommand cmd = new MySqlCommand();
        connection.OpenConnection(true);
        totalRecords = PersonalizationProviderProcedures.myaspnet_PersonalizationAdministration_FindState(true, ApplicationId, ApplicationName, pageIndex, pageSize,
                       path, null, DateTime.MinValue, connection, ref cmd);

        PersonalizationStateInfoCollection sharedStateInfoCollection = new PersonalizationStateInfoCollection();

        using (var reader = cmd.ExecuteReader())
        {
          while (reader.Read())
          {
            string pathQuery = reader.GetString("Path");
            DateTime lastUpdatedDate = (reader.IsDBNull(1)) ? DateTime.MinValue :
                                         DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
            int size = (reader.IsDBNull(2)) ? 0 : reader.GetInt32("SharedDataLength");
            int userDataLength = (reader.IsDBNull(3)) ? 0 : reader.GetInt32("UserDataLength");
            int userCount = (reader.IsDBNull(4)) ? 0 : reader.GetInt32("UserCount");

            sharedStateInfoCollection.Add(new SharedPersonalizationStateInfo(
                                    pathQuery, lastUpdatedDate, size, userDataLength, userCount));
          }
        }
        connection.CloseConnection();
        return sharedStateInfoCollection;
      }
      catch (Exception ex)
      {
        if (writeExceptionsToEventLog)
          WriteToEventLog(ex, "MySQLPersonalizationProvider - FindSharedState");        
        throw;
      }
      finally
      {
        connection.CloseConnection();
      }
    }
 private PersonalizationStateInfoCollection FindSharedState(string path, int pageIndex, int pageSize, out int totalRecords)
 {
     SqlConnectionHolder connectionHolder = null;
     SqlConnection connection = null;
     SqlDataReader reader = null;
     PersonalizationStateInfoCollection infos2;
     totalRecords = 0;
     try
     {
         try
         {
             connectionHolder = this.GetConnectionHolder();
             connection = connectionHolder.Connection;
             this.CheckSchemaVersion(connection);
             SqlCommand command = new SqlCommand("dbo.aspnet_PersonalizationAdministration_FindState", connection);
             this.SetCommandTypeAndTimeout(command);
             SqlParameterCollection parameters = command.Parameters;
             parameters.Add(new SqlParameter("AllUsersScope", SqlDbType.Bit)).Value = true;
             parameters.AddWithValue("ApplicationName", this.ApplicationName);
             parameters.AddWithValue("PageIndex", pageIndex);
             parameters.AddWithValue("PageSize", pageSize);
             SqlParameter parameter2 = new SqlParameter("@ReturnValue", SqlDbType.Int) {
                 Direction = ParameterDirection.ReturnValue
             };
             parameters.Add(parameter2);
             SqlParameter parameter = parameters.Add("Path", SqlDbType.NVarChar);
             if (path != null)
             {
                 parameter.Value = path;
             }
             parameter = parameters.Add("UserName", SqlDbType.NVarChar);
             parameter = parameters.Add("InactiveSinceDate", SqlDbType.DateTime);
             reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
             PersonalizationStateInfoCollection infos = new PersonalizationStateInfoCollection();
             if (reader != null)
             {
                 if (reader.HasRows)
                 {
                     while (reader.Read())
                     {
                         string str = reader.GetString(0);
                         DateTime lastUpdatedDate = reader.IsDBNull(1) ? DateTime.MinValue : DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
                         int size = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                         int sizeOfPersonalizations = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                         int countOfPersonalizations = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                         infos.Add(new SharedPersonalizationStateInfo(str, lastUpdatedDate, size, sizeOfPersonalizations, countOfPersonalizations));
                     }
                 }
                 reader.Close();
                 reader = null;
             }
             if ((parameter2.Value != null) && (parameter2.Value is int))
             {
                 totalRecords = (int) parameter2.Value;
             }
             infos2 = infos;
         }
         finally
         {
             if (reader != null)
             {
                 reader.Close();
             }
             if (connectionHolder != null)
             {
                 connectionHolder.Close();
                 connectionHolder = null;
             }
         }
     }
     catch
     {
         throw;
     }
     return infos2;
 }
        private PersonalizationStateInfoCollection FindUserState(string path,
            DateTime inactiveSinceDate,
            string username,
            int pageIndex,
            int pageSize,
            out int totalRecords)
        {
            SqlConnectionHolder connectionHolder = null;
            MySqlConnection connection = null;
            MySqlDataReader reader = null;
            totalRecords = 0;

            try {
                try {
                    connectionHolder = GetConnectionHolder();
                    connection = connectionHolder.Connection;

                    CheckSchemaVersion( connection );

                    MySqlCommand command = new MySqlCommand(); //"dbo.aspnet_PersonalizationAdministration_FindState", connection);

                    totalRecords = MySqlStoredProcedures.aspnet_PersonalizationAdministration_FindState(false,
                            ApplicationName, pageIndex, pageSize, path, username, inactiveSinceDate, connectionHolder,
                            ref command);

                    SetCommandTypeAndTimeout(command);
                    //MySqlParameterCollection parameters = command.Parameters;

                    //MySqlParameter parameter = parameters.Add(new MySqlParameter("AllUsersScope", MySqlDbType.Bit));
                    //parameter.Value = false;

                    //parameters.AddWithValue("ApplicationName", ApplicationName);
                    //parameters.AddWithValue("PageIndex", pageIndex);
                    //parameters.AddWithValue("PageSize", pageSize);

                    //MySqlParameter returnValue = new MySqlParameter("@ReturnValue", MySqlDbType.Int32);
                    //returnValue.Direction = ParameterDirection.ReturnValue;
                    //parameters.Add(returnValue);

                    //parameter = parameters.Add("Path", MySqlDbType.VarChar);
                    //if (path != null) {
                    //    parameter.Value = path;
                    //}

                    //parameter = parameters.Add("UserName", MySqlDbType.VarChar);
                    //if (username != null) {
                    //    parameter.Value = username;
                    //}

                    //parameter = parameters.Add("InactiveSinceDate", MySqlDbType.DateTime);
                    //if (inactiveSinceDate != DefaultInactiveSinceDate) {
                    //    parameter.Value = inactiveSinceDate.ToUniversalTime();
                    //}

                    reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                    PersonalizationStateInfoCollection stateInfoCollection = new PersonalizationStateInfoCollection();

                    if (reader != null) {
                        if (reader.HasRows) {
                            while(reader.Read()) {
                                string returnedPath = reader.GetString(0);
                                DateTime lastUpdatedDate = DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
                                int size = reader.GetInt32(2);
                                string returnedUsername = reader.GetString(3);
                                DateTime lastActivityDate = DateTime.SpecifyKind(reader.GetDateTime(4), DateTimeKind.Utc);
                                stateInfoCollection.Add(new UserPersonalizationStateInfo(
                                                                returnedPath, lastUpdatedDate,
                                                                size, returnedUsername, lastActivityDate));
                            }
                        }

                        // The reader needs to be closed so return value can be accessed
                        // See MSDN doc for MySqlParameter.Direction for details.
                        reader.Close();
                        reader = null;
                    }

                    // Set the total count at the end after all operations pass
                    //if (returnValue.Value != null && returnValue.Value is int) {
                    //    totalRecords = (int)returnValue.Value;
                    //}

                    return stateInfoCollection;
                }
                finally {
                    if (reader != null) {
                        reader.Close();
                    }

                    if (connectionHolder != null) {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch {
                throw;
            }
        }
        private PersonalizationStateInfoCollection FindUserState(string path, DateTime inactiveSinceDate, string username, int pageIndex, int pageSize, out int totalRecords)
        {
            PersonalizationStateInfoCollection infos2 = null;
            totalRecords = 0;

            using (TransactionContextFactory.EnterContext(TransactionAffinity.NotSupported))
            {
                IDataSource datasource = DataSourceFactory.GetDataSource("PersonalizationProvider");
                IDataCommand cmd = datasource.GetCommand("aspnet_PersonalizationAdministration_FindState");
                cmd.DbCommand.CommandTimeout = this._commandTimeout;

                cmd.Parameters["AllUsersScope"].Value = false;
                cmd.Parameters["ApplicationName"].Value = this.ApplicationName;
                cmd.Parameters["PageIndex"].Value = pageIndex;
                cmd.Parameters["PageSize"].Value = pageSize;

                if (path != null)
                    cmd.Parameters["Path"].Value = path;

                if (username != null)
                    cmd.Parameters["UserName"].Value = username;

                if (inactiveSinceDate != DateTime.MaxValue)
                    cmd.Parameters["InactiveSinceDate"].Value = inactiveSinceDate.ToUniversalTime();

                IDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

                try
                {
                    PersonalizationStateInfoCollection infos = new PersonalizationStateInfoCollection();

                    while (reader.Read())
                    {
                        string str = reader.GetString(0);
                        DateTime lastUpdatedDate = DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
                        int size = reader.GetInt32(2);
                        string str2 = reader.GetString(3);
                        DateTime lastActivityDate = DateTime.SpecifyKind(reader.GetDateTime(4), DateTimeKind.Utc);
                        infos.Add(new UserPersonalizationStateInfo(str, lastUpdatedDate, size, str2, lastActivityDate));
                    }

                    if ((cmd.Parameters["ReturnValue"].Value != null) && (cmd.Parameters["ReturnValue"].Value is int))
                        totalRecords = (int)cmd.Parameters["ReturnValue"].Value;

                    infos2 = infos;
                }
                finally
                {
                    if (!reader.IsClosed)
                        reader.Close();
                }
            }

            return infos2;
        }
        // Methods
        private PersonalizationStateInfoCollection FindSharedState(string path, int pageIndex, int pageSize, out int totalRecords)
        {
            PersonalizationStateInfoCollection infos2 = null;
            totalRecords = 0;

            using (TransactionContextFactory.EnterContext(TransactionAffinity.NotSupported))
            {
                IDataSource datasource = DataSourceFactory.GetDataSource("PersonalizationProvider");
                IDataCommand cmd = datasource.GetCommand("aspnet_PersonalizationAdministration_FindState");

                cmd.DbCommand.CommandTimeout = this._commandTimeout;
                cmd.Parameters["AllUsersScope"].Value = true;
                cmd.Parameters["ApplicationName"].Value = this.ApplicationName;
                cmd.Parameters["PageIndex"].Value = pageIndex;
                cmd.Parameters["PageSize"].Value = pageSize;

                if (path != null)
                    cmd.Parameters["Path"].Value = path;

                IDataReader reader =  cmd.ExecuteReader(CommandBehavior.SequentialAccess);

                try
                {
                    PersonalizationStateInfoCollection infos = new PersonalizationStateInfoCollection();

                    while (reader.Read())
                    {
                        string str = reader.GetString(0);
                        DateTime lastUpdatedDate = reader.IsDBNull(1) ? DateTime.MinValue : DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
                        int size = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                        int sizeOfPersonalizations = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        int countOfPersonalizations = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        infos.Add(new SharedPersonalizationStateInfo(str, lastUpdatedDate, size, sizeOfPersonalizations, countOfPersonalizations));
                    }

                    if ((cmd.Parameters["ReturnValue"].Value != null) && (cmd.Parameters["ReturnValue"].Value is int))
                        totalRecords = (int)cmd.Parameters["ReturnValue"].Value;

                    infos2 = infos;
                }
                finally
                {
                    if (!reader.IsClosed)
                        reader.Close();
                }
            }

            return infos2;
        }