private StringBuilder CreateRawCacheKey()
        {
            // Note: The cache key will contain information such as server names and
            // passwords, however it will be stored in the internal cache, which is
            // not accessible to page developers, so it is secure.
            StringBuilder sb = new StringBuilder(CacheInternal.PrefixDataSourceControl, 1024);

            sb.Append(GetType().GetHashCode().ToString(CultureInfo.InvariantCulture));

            sb.Append(CacheDuration.ToString(CultureInfo.InvariantCulture));
            sb.Append(':');
            sb.Append(((int)CacheExpirationPolicy).ToString(CultureInfo.InvariantCulture));

            SqlDataSourceCache sqlCache = Cache as SqlDataSourceCache;

            if (sqlCache != null)
            {
                sb.Append(":");
                sb.Append(sqlCache.SqlCacheDependency);
            }

            sb.Append(":");
            sb.Append(ConnectionString);
            sb.Append(":");
            sb.Append(SelectCommand);
            //sb.Append(SelectCountCommand);

            // Append parameter names and values
            if (SelectParameters.Count > 0)
            {
                sb.Append("?");
                IDictionary parameters = SelectParameters.GetValues(Context, this);
                foreach (DictionaryEntry entry in parameters)
                {
                    sb.Append(entry.Key.ToString());
                    if ((entry.Value != null) && (entry.Value != DBNull.Value))
                    {
                        sb.Append("=");
                        sb.Append(entry.Value.ToString());
                    }
                    else
                    {
                        if (entry.Value == DBNull.Value)
                        {
                            sb.Append("(dbnull)");
                        }
                        else
                        {
                            sb.Append("(null)");
                        }
                    }
                    sb.Append("&");
                }
            }
            return(sb);
        }
        protected internal override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            SqlCacheDependency dependency;

            if (this.SelectCommand.Length == 0)
            {
                return(null);
            }
            DbConnection connection = this._owner.CreateConnection(this._owner.ConnectionString);

            if (connection == null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("SqlDataSourceView_CouldNotCreateConnection", new object[] { this._owner.ID }));
            }
            DataSourceCache cache          = this._owner.Cache;
            bool            flag           = (cache != null) && cache.Enabled;
            string          sortExpression = arguments.SortExpression;

            if (this.CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }
            if (this.CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }
            if (this.CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }
            if (flag)
            {
                if (this._owner.DataSourceMode != SqlDataSourceMode.DataSet)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_CacheNotSupported", new object[] { this._owner.ID }));
                }
                arguments.RaiseUnsupportedCapabilitiesError(this);
                DataSet set = this._owner.LoadDataFromCache(0, -1) as DataSet;
                if (set != null)
                {
                    IOrderedDictionary parameterValues = this.FilterParameters.GetValues(this._context, this._owner);
                    if (this.FilterExpression.Length > 0)
                    {
                        SqlDataSourceFilteringEventArgs args = new SqlDataSourceFilteringEventArgs(parameterValues);
                        this.OnFiltering(args);
                        if (args.Cancel)
                        {
                            return(null);
                        }
                    }
                    return(FilteredDataSetHelper.CreateFilteredDataView(set.Tables[0], sortExpression, this.FilterExpression, parameterValues));
                }
            }
            DbCommand command = this._owner.CreateCommand(this.SelectCommand, connection);

            this.InitializeParameters(command, this.SelectParameters, null);
            command.CommandType = GetCommandType(this.SelectCommandType);
            SqlDataSourceSelectingEventArgs e = new SqlDataSourceSelectingEventArgs(command, arguments);

            this.OnSelecting(e);
            if (e.Cancel)
            {
                return(null);
            }
            string sortParameterName = this.SortParameterName;

            if (sortParameterName.Length > 0)
            {
                if (command.CommandType != CommandType.StoredProcedure)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_SortParameterRequiresStoredProcedure", new object[] { this._owner.ID }));
                }
                command.Parameters.Add(this._owner.CreateParameter(this.ParameterPrefix + sortParameterName, sortExpression));
                arguments.SortExpression = string.Empty;
            }
            arguments.RaiseUnsupportedCapabilitiesError(this);
            sortExpression = arguments.SortExpression;
            if (this.CancelSelectOnNullParameter)
            {
                int count = command.Parameters.Count;
                for (int i = 0; i < count; i++)
                {
                    DbParameter parameter = command.Parameters[i];
                    if (((parameter != null) && (parameter.Value == null)) && ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput)))
                    {
                        return(null);
                    }
                }
            }
            this.ReplaceNullValues(command);
            IEnumerable enumerable = null;

            switch (this._owner.DataSourceMode)
            {
            case SqlDataSourceMode.DataReader:
            {
                if (this.FilterExpression.Length > 0)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_FilterNotSupported", new object[] { this._owner.ID }));
                }
                if (sortExpression.Length > 0)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_SortNotSupported", new object[] { this._owner.ID }));
                }
                bool flag4 = false;
                try
                {
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }
                    enumerable = command.ExecuteReader(CommandBehavior.CloseConnection);
                    flag4      = true;
                    SqlDataSourceStatusEventArgs args6 = new SqlDataSourceStatusEventArgs(command, 0, null);
                    this.OnSelected(args6);
                }
                catch (Exception exception2)
                {
                    bool flag5;
                    if (!flag4)
                    {
                        SqlDataSourceStatusEventArgs args7 = new SqlDataSourceStatusEventArgs(command, 0, exception2);
                        this.OnSelected(args7);
                        if (!args7.ExceptionHandled)
                        {
                            throw;
                        }
                        return(enumerable);
                    }
                    exception2 = this.BuildCustomException(exception2, DataSourceOperation.Select, command, out flag5);
                    if (flag5)
                    {
                        throw exception2;
                    }
                    throw;
                }
                return(enumerable);
            }

            case SqlDataSourceMode.DataSet:
                dependency = null;
                if (flag && (cache is SqlDataSourceCache))
                {
                    SqlDataSourceCache cache2 = (SqlDataSourceCache)cache;
                    if (string.Equals(cache2.SqlCacheDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase))
                    {
                        if (!(command is SqlCommand))
                        {
                            throw new InvalidOperationException(System.Web.SR.GetString("SqlDataSourceView_CommandNotificationNotSupported", new object[] { this._owner.ID }));
                        }
                        dependency = new SqlCacheDependency((SqlCommand)command);
                        break;
                    }
                }
                break;

            default:
                return(enumerable);
            }
            DbDataAdapter adapter      = this._owner.CreateDataAdapter(command);
            DataSet       dataSet      = new DataSet();
            int           affectedRows = 0;
            bool          flag2        = false;

            try
            {
                affectedRows = adapter.Fill(dataSet, base.Name);
                flag2        = true;
                SqlDataSourceStatusEventArgs args3 = new SqlDataSourceStatusEventArgs(command, affectedRows, null);
                this.OnSelected(args3);
            }
            catch (Exception exception)
            {
                if (flag2)
                {
                    bool flag3;
                    exception = this.BuildCustomException(exception, DataSourceOperation.Select, command, out flag3);
                    if (flag3)
                    {
                        throw exception;
                    }
                    throw;
                }
                SqlDataSourceStatusEventArgs args4 = new SqlDataSourceStatusEventArgs(command, affectedRows, exception);
                this.OnSelected(args4);
                if (!args4.ExceptionHandled)
                {
                    throw;
                }
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            DataTable table = (dataSet.Tables.Count > 0) ? dataSet.Tables[0] : null;

            if (flag && (table != null))
            {
                this._owner.SaveDataToCache(0, -1, dataSet, dependency);
            }
            if (table == null)
            {
                return(enumerable);
            }
            IOrderedDictionary values = this.FilterParameters.GetValues(this._context, this._owner);

            if (this.FilterExpression.Length > 0)
            {
                SqlDataSourceFilteringEventArgs args5 = new SqlDataSourceFilteringEventArgs(values);
                this.OnFiltering(args5);
                if (args5.Cancel)
                {
                    return(null);
                }
            }
            return(FilteredDataSetHelper.CreateFilteredDataView(table, sortExpression, this.FilterExpression, values));
        }