Example #1
0
        /// <summary>
        /// Updates the property on the database with the name <paramref name="databaseName"/>.
        /// </summary>
        /// <param name="databaseName">The database to update.</param>
        /// <param name="newDatabaseName">
        /// The new database name, or <c>null</c> to not update.
        /// </param>
        /// <param name="databaseMaxSize">
        /// The new database max size, or <c>null</c> to not update.
        /// </param>
        /// <param name="databaseEdition">
        /// The new database edition, or <c>null</c> to not update.
        /// </param>
        /// <param name="serviceObjective">
        /// The new service objective, or <c>null</c> to not update.
        /// </param>
        /// <returns>The updated database object.</returns>
        public Database UpdateDatabase(
            string databaseName,
            string newDatabaseName,
            int?databaseMaxSize,
            DatabaseEdition?databaseEdition,
            ServiceObjective serviceObjective)
        {
            // Find the database by name
            Database database = GetDatabase(databaseName);

            // Update the name if specified
            if (newDatabaseName != null)
            {
                database.Name = newDatabaseName;
            }

            // Update the max size and edition properties
            database.MaxSizeGB = databaseMaxSize;
            database.Edition   = databaseEdition == null ? null : databaseEdition.ToString();

            database.IsRecursiveTriggersOn = null;

            // Update the service objective property if specified
            if (serviceObjective != null)
            {
                database.ServiceObjectiveId = serviceObjective.Id;
            }

            // Mark the database object for update and submit the changes
            this.UpdateObject(database);
            try
            {
                this.SaveChanges();
            }
            catch
            {
                this.RevertChanges(database);
                throw;
            }

            return(this.GetDatabase(database.Name));
        }
        /// <summary>
        /// Update a database on the server.
        /// </summary>
        /// <param name="databaseName">The name of the database to modify</param>
        /// <param name="newDatabaseName">The new name of the database</param>
        /// <param name="databaseMaxSize">The new maximum size of the database</param>
        /// <param name="databaseEdition">The new edition of the database</param>
        /// <returns>The updated database</returns>
        public Database UpdateDatabase(
            string databaseName,
            string newDatabaseName,
            int? databaseMaxSize,
            DatabaseEdition? databaseEdition,
            ServiceObjective serviceObjective)
        {
            this.clientRequestId = SqlDatabaseManagementHelper.GenerateClientTracingId();

            ISqlDatabaseManagement channel = GetManagementChannel();

            Database database = this.GetDatabase(databaseName);

            //make sure the database exists.
            if (database == null)
            {
                throw new Exception(
                    "Error: Result of GetDatabase() in ServerDataServiceCertAuth.UpdateDatabase() is null");
            }

            SqlDatabaseInput input = new SqlDatabaseInput();

            //Set the database ID and collation
            input.Id = database.Id.ToString();
            input.CollationName = database.CollationName;

            if (serviceObjective != null)
            {
                input.ServiceObjectiveId = serviceObjective.Id.ToString();
            }

            //Determine what the new name for the database should be
            if (!string.IsNullOrEmpty(newDatabaseName))
            {
                input.Name = newDatabaseName;
            }
            else
            {
                input.Name = database.Name;
            }

            //Determine what the new edition for the database should be
            if (databaseEdition.HasValue && (databaseEdition != DatabaseEdition.None))
            {
                input.Edition = databaseEdition.ToString();
            }
            else
            {
                input.Edition = database.Edition;
            }

            //Determine what the new maximum size for the database should be.
            if (databaseMaxSize.HasValue)
            {
                input.MaxSizeGB = databaseMaxSize.ToString();
            }
            else
            {
                input.MaxSizeGB = database.MaxSizeGB.ToString();
            }

            //Send the update request and wait for the response.
            SqlDatabaseResponse response = channel.EndUpdateDatabase(
                channel.BeginUpdateDatabase(
                    this.subscriptionId,
                    this.serverName,
                    databaseName,
                    input,
                    null,
                    null));

            //Transform the response into a database object.
            Database updatedDatabase = CreateDatabaseFromResponse(response);

            return updatedDatabase;
        }
Example #3
0
        /// <summary>
        /// Update a database on the server.
        /// </summary>
        /// <param name="databaseName">The name of the database to modify</param>
        /// <param name="newDatabaseName">The new name of the database</param>
        /// <param name="databaseMaxSize">The new maximum size of the database</param>
        /// <param name="databaseEdition">The new edition of the database</param>
        /// <returns>The updated database</returns>
        public Database UpdateDatabase(
            string databaseName,
            string newDatabaseName,
            int?databaseMaxSize,
            DatabaseEdition?databaseEdition,
            ServiceObjective serviceObjective)
        {
            this.clientRequestId = SqlDatabaseManagementHelper.GenerateClientTracingId();

            ISqlDatabaseManagement channel = GetManagementChannel();

            Database database = this.GetDatabase(databaseName);

            //make sure the database exists.
            if (database == null)
            {
                throw new Exception(
                          "Error: Result of GetDatabase() in ServerDataServiceCertAuth.UpdateDatabase() is null");
            }

            SqlDatabaseInput input = new SqlDatabaseInput();

            //Set the database ID and collation
            input.Id            = database.Id.ToString();
            input.CollationName = database.CollationName;

            if (serviceObjective != null)
            {
                input.ServiceObjectiveId = serviceObjective.Id.ToString();
            }

            //Determine what the new name for the database should be
            if (!string.IsNullOrEmpty(newDatabaseName))
            {
                input.Name = newDatabaseName;
            }
            else
            {
                input.Name = database.Name;
            }

            //Determine what the new edition for the database should be
            if (databaseEdition.HasValue && (databaseEdition != DatabaseEdition.None))
            {
                input.Edition = databaseEdition.ToString();
            }
            else
            {
                input.Edition = database.Edition;
            }

            //Determine what the new maximum size for the database should be.
            if (databaseMaxSize.HasValue)
            {
                input.MaxSizeGB = databaseMaxSize.ToString();
            }
            else
            {
                input.MaxSizeGB = database.MaxSizeGB.ToString();
            }

            //Send the update request and wait for the response.
            SqlDatabaseResponse response = channel.EndUpdateDatabase(
                channel.BeginUpdateDatabase(
                    this.subscriptionId,
                    this.serverName,
                    databaseName,
                    input,
                    null,
                    null));

            //Transform the response into a database object.
            Database updatedDatabase = CreateDatabaseFromResponse(response);

            return(updatedDatabase);
        }
        /// <summary>
        /// Updates the property on the database with the name <paramref name="databaseName"/>.
        /// </summary>
        /// <param name="databaseName">The database to update.</param>
        /// <param name="newDatabaseName">
        /// The new database name, or <c>null</c> to not update.
        /// </param>
        /// <param name="databaseMaxSize">
        /// The new database max size, or <c>null</c> to not update.
        /// </param>
        /// <param name="databaseEdition">
        /// The new database edition, or <c>null</c> to not update.
        /// </param>
        /// <param name="serviceObjective">
        /// The new service objective, or <c>null</c> to not update.
        /// </param>
        /// <returns>The updated database object.</returns>
        public Database UpdateDatabase(
            string databaseName,
            string newDatabaseName,
            int? databaseMaxSize,
            DatabaseEdition? databaseEdition,
            ServiceObjective serviceObjective)
        {
            // Find the database by name
            Database database = GetDatabase(databaseName);

            // Update the name if specified
            if (newDatabaseName != null)
            {
                database.Name = newDatabaseName;
            }

            // Update the max size and edition properties
            database.MaxSizeGB = databaseMaxSize;
            database.Edition = databaseEdition == null ? null : databaseEdition.ToString();

            database.IsRecursiveTriggersOn = null;

            // Update the service objective property if specified
            if (serviceObjective != null)
            {
                database.ServiceObjectiveId = serviceObjective.Id;
            }

            // Mark the database object for update and submit the changes
            this.UpdateObject(database);
            try
            {
                this.SaveChanges();
            }
            catch
            {
                this.RevertChanges(database);
                throw;
            }

            return this.GetDatabase(database.Name);
        }