コード例 #1
0
        /// <summary>
        /// Raises an event requesting database authorization. If authorization
        /// succeeds, the database connection is recreated so the original
        /// operation can be retried.
        /// </summary>
        /// <param name="error">The original error that caused the authorization
        /// request.
        /// </param>
        /// <exception cref="DatabaseException">Thrown if the reauthorization
        /// attempt fails.
        /// </exception>
        /// <revision revisor="dev22" date="03/08/2010" version="1.1.7.15">
        /// Member added. (work for US577).
        /// </revision>
        private void Reauthorize(SqlException error)
        {
            var eventData =
                new AuthorizationEventArgs(this.dataServiceDefinition);

            if (this.AuthorizationRequired != null)
            {
                try
                {
                    this.AuthorizationRequired(this, eventData);
                }
                catch (Exception ex)
                {
                    throw new DatabaseException(
                              String.Format(
                                  "{0} {1}",
                                  Properties.Resources.ErrorStartMessage,
                                  Properties.Resources.ReauthorizationErrorMessage),
                              ex);
                }
            }

            if (eventData.New == null)
            {
                throw error.ToDBError(
                          String.Format(
                              "{0} {1}",
                              Properties.Resources.ErrorStartMessage,
                              Properties.Resources.MissingAuthorizationHandlerMessage));
            }

            this.dataServiceDefinition.Username       = eventData.New.Username;
            this.dataServiceDefinition.SecureUsername = eventData.New.Username;

            this.dataServiceDefinition.Password       = eventData.New.Password;
            this.dataServiceDefinition.SecurePassword = eventData.New.Password;

            this.CreateDatabase(this.dataServiceDefinition);
        }