I am having a heck of a time using SMO in C# to drop a database that is joined to an Availability Group. This is currently being done using dynamic SQL and we do the following...
for each secondary
ALTER DATABASE db SET HADR OFF
DROP db
on primary
ALTER AVAILABILITY GROUP ag REMOVE DATABASE db
DROP db
I am trying to replicate this behavior in SMO, but nothing seems to work. I've tried every combination of SuspendDataMovement, LeaveAvailabilityGroup and Drop that I can think of, and each time I just get back a FailedOperationException that says that the operation failed, but does not provide any more information. Does anyone have any experience using SMO to drop a database that is joined to Availability Group, and, if so, can they please share it with me?