/// <summary> /// Remove a database from a server /// </summary> /// <param name="databaseName">The name of the database to delete</param> public void RemoveDatabase(string databaseName) { this.clientRequestId = SqlDatabaseManagementHelper.GenerateClientTracingId(); ISqlDatabaseManagement channel = GetManagementChannel(); Database database = this.GetDatabase(databaseName); SqlDatabaseInput input = new SqlDatabaseInput(); input.Name = databaseName; input.Id = database.Id.ToString(); input.CollationName = database.CollationName; input.Edition = database.Edition.ToString(); input.MaxSizeGB = database.MaxSizeGB.ToString(); channel.EndRemoveDatabase( channel.BeginRemoveDatabase( this.subscriptionId, this.serverName, databaseName, input, null, null)); }
/// <summary> /// A mock call to BeginNewDatabase /// </summary> /// <param name="subscriptionId">The subscription Id to pass through</param> /// <param name="serverName">The server name to pass through</param> /// <param name="input">The input object to pass through</param> /// <param name="callback">The callback object to pass through</param> /// <param name="state">The state object to pass through</param> /// <returns>An <see cref="IAsyncResult"/> of the mock request</returns> public IAsyncResult BeginNewDatabase( string subscriptionId, string serverName, SqlDatabaseInput input, AsyncCallback callback, object state) { SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult(); result.Values["subscriptionId"] = subscriptionId; result.Values["serverName"] = serverName; result.Values["input"] = input; result.Values["callback"] = callback; result.Values["state"] = state; return(result); }
/// <summary> /// Creates a new sql database. /// </summary> /// <param name="databaseName">The name for the new database</param> /// <param name="databaseMaxSize">The maximum size of the new database</param> /// <param name="databaseCollation">The collation for the new database</param> /// <param name="databaseEdition">The edition for the new database</param> /// <returns>The newly created Sql Database</returns> public Database CreateNewDatabase( string databaseName, int?databaseMaxSize, string databaseCollation, DatabaseEdition databaseEdition) { this.clientRequestId = SqlDatabaseManagementHelper.GenerateClientTracingId(); ISqlDatabaseManagement channel = GetManagementChannel(); SqlDatabaseInput input = new SqlDatabaseInput(); input.Name = databaseName; input.CollationName = databaseCollation ?? string.Empty; //determine the edition if (databaseEdition != DatabaseEdition.None) { input.Edition = databaseEdition.ToString(); } else { input.Edition = string.Empty; } //determine the maximum size if (databaseMaxSize.HasValue) { input.MaxSizeGB = databaseMaxSize.ToString(); } //create a new database on the server SqlDatabaseResponse response = channel.EndNewDatabase( channel.BeginNewDatabase(this.subscriptionId, this.serverName, input, null, null)); Database database = CreateDatabaseFromResponse(response); return(database); }
/// <summary> /// A mock call to BeginUpdateDatabase /// </summary> /// <param name="subscriptionId">The subscription Id to pass through</param> /// <param name="serverName">The server name to pass through</param> /// <param name="databaseName">The name of the database to pass through</param> /// <param name="input">the input object to pass through</param> /// <param name="callback">the callback object to pass through</param> /// <param name="state">the state object to pass through</param> /// <returns>An <see cref="IAsyncResult"/> of the mock request</returns> public IAsyncResult BeginUpdateDatabase( string subscriptionId, string serverName, string databaseName, SqlDatabaseInput input, AsyncCallback callback, object state) { SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult(); result.Values["subscriptionId"] = subscriptionId; result.Values["serverName"] = serverName; result.Values["databaseName"] = databaseName; result.Values["input"] = input; result.Values["callback"] = callback; result.Values["state"] = state; return result; }
/// <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> /// Creates a new sql database. /// </summary> /// <param name="databaseName">The name for the new database</param> /// <param name="databaseMaxSize">The maximum size of the new database</param> /// <param name="databaseCollation">The collation for the new database</param> /// <param name="databaseEdition">The edition for the new database</param> /// <returns>The newly created Sql Database</returns> public Database CreateNewDatabase( string databaseName, int? databaseMaxSize, string databaseCollation, DatabaseEdition databaseEdition) { this.clientRequestId = SqlDatabaseManagementHelper.GenerateClientTracingId(); ISqlDatabaseManagement channel = GetManagementChannel(); SqlDatabaseInput input = new SqlDatabaseInput(); input.Name = databaseName; input.CollationName = databaseCollation ?? string.Empty; //determine the edition if (databaseEdition != DatabaseEdition.None) { input.Edition = databaseEdition.ToString(); } else { input.Edition = string.Empty; } //determine the maximum size if (databaseMaxSize.HasValue) { input.MaxSizeGB = databaseMaxSize.ToString(); } //create a new database on the server SqlDatabaseResponse response = channel.EndNewDatabase( channel.BeginNewDatabase(this.subscriptionId, this.serverName, input, null, null)); Database database = CreateDatabaseFromResponse(response); return database; }
/// <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); }