private static void AddAzureProperties(DatabaseInfo databaseInfo, DatabasePrototypeAzure prototype) { if (prototype == null) { return; } databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.AzureEdition, prototype.AzureEditionDisplay); databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.ServiceLevelObjective, prototype.CurrentServiceLevelObjective); }
/// <summary> /// Commit changes to the database /// </summary> /// <param name="marshallingControl">The control through which UI interactions are to be marshalled</param> /// <returns>The SMO database object that was created or modified</returns> public override Database ApplyChanges() { // For v12 Non-DW DBs lets use SMO if (this.ServerVersion.Major >= 12 && this.AzureEdition != AzureEdition.DataWarehouse) { return(base.ApplyChanges()); } //Note : We purposely don't call base.ApplyChanges() here since SMO doesn't fully support Azure yet and so will throw //an error if we try to modify the Database object directly string alterDbPropertiesStatement = DatabasePrototypeAzure.CreateModifyAzureDbOptionsStatement(this.Name, this.AzureEdition, this.MaxSize, this.CurrentServiceLevelObjective); if (this.AzureEdition == AzureEdition.DataWarehouse) { alterDbPropertiesStatement = DatabasePrototypeAzure.CreateModifySqlDwDbOptionsStatement(this.Name, this.MaxSize, this.CurrentServiceLevelObjective); } string alterAzureDbRecursiveTriggersEnabledStatement = DatabasePrototypeAzure.CreateAzureDbSetRecursiveTriggersStatement(this.Name, this.RecursiveTriggers); string alterAzureDbIsReadOnlyStatement = DatabasePrototypeAzure.CreateAzureDbSetIsReadOnlyStatement(this.Name, this.IsReadOnly); Database db = this.GetDatabase(); //Altering the DB needs to be done on the master DB using (var conn = new SqlConnection(this.context.ServerConnection.GetDatabaseConnection("master").ConnectionString)) { var cmd = new SqlCommand(); cmd.Connection = conn; conn.Open(); //Only run the alter statements for modifications made. This is mostly to allow the non-Azure specific //properties to be updated when a SLO change is in progress, but it also is beneficial to save trips to the //server whenever we can (especially when Azure is concerned) if (currentState.azureEdition != originalState.azureEdition || currentState.currentServiceLevelObjective != originalState.currentServiceLevelObjective || currentState.maxSize != originalState.maxSize) { cmd.CommandText = alterDbPropertiesStatement; cmd.ExecuteNonQuery(); } if (currentState.recursiveTriggers != originalState.recursiveTriggers) { cmd.CommandText = alterAzureDbRecursiveTriggersEnabledStatement; cmd.ExecuteNonQuery(); } if (currentState.isReadOnly != originalState.isReadOnly) { cmd.CommandText = alterAzureDbIsReadOnlyStatement; cmd.ExecuteNonQuery(); } } //Because we didn't use SMO to do the alter we should refresh the DB object so it picks up the correct properties db.Refresh(); // For properties that are supported in Database.Alter(), call SaveProperties, and then alter the DB. // if (this.AzureEdition != AzureEdition.DataWarehouse) { this.SaveProperties(db); db.Alter(TerminationClause.FailOnOpenTransactions); } return(db); }