public void DeleteUser(string userPrincipalName) { CPDatabase database = null; ADUser ldapUser = null; try { ldapUser = new ADUser(StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.PrimaryDC); ldapUser.DeleteUser(userPrincipalName); // Delete from database database = new CPDatabase(); database.DeleteUser(userPrincipalName); } catch (Exception ex) { ThrowEvent(AlertID.FAILED, ex.Message); } finally { if (ldapUser != null) { ldapUser.Dispose(); } if (database != null) { database.Dispose(); } } }