コード例 #1
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);
        }