I have a C# scheduled task which runs every night and includes a kill command to drop an existing database so that it can be recreated. It randomly generates this error about once a week.
Kill database failed. User does not have permission to alter database 'Foo', the database does not exist, or the database is not in a state that allows access checks. Kill database failed.
The C# used is as follows.
So I am already trying to kill all of the processes. Are there any other checks or commands I could do before the kill command to ensure it happens successfully? It can't be a user permission problem as the operation works most of the time so what could be causing the "not in a state that allows access checks"?