Sorry, I don't visit here that often. This is what I use and yes, there is a small timing window that someone could reestablish a connection. You could check the db.activeconnections and if it is greater than zero, retry the sequence. The offline clears active connections "gracefully" and the online seems to tell SQL that it can take control of the database filegroups and files again. Without the db.online the files are not deleted.
Regards, Ira Grollman, OMKT LLC
'requires references in your project to the two dll's that these live in
'pick whatever server you are using...
Dim smoServer As Server = New Server(".\SQLExpress")
Public Function blnDropDatabase(ByVal strName As String, ByVal smoServer As Server) As Boolean
For Each db As Microsoft.SqlServer.Management.Smo.Database In smoServer.Databases
If LCase(db.Name) = LCase(strName) Then
Catch ex As Exception
'Unable to drop