when I'm trying to delete a database using c#, method
Microsoft.SqlServer.Management.Smo.Server.KillDatabase(String database).
it fails. Error message is
System.Data.SqlClient.SqlException: User does not have permission to alter database 'My_Database_Name', the database does not exist, or the database is not in a state that allows access checks. ALTER DATABASE statement failed.".
Things I know :
1) Database exists;
2) Login name and password are correct;
3) Before it worked good, but after i added 3 additional tables to the database, it stopped working.
What could be the reason, why it fails to delete a database ?
My code is :
if (server.Databases.Contains(databaseName))
{
server.KillDatabase(databaseName);
}
masterdatabase instead of theMy_Database_Name. I think the biggest suspect is your permissions on this server.or the database is not in a state that allows access checks. ALTER DATABASE statement failed.".this line here makes me think you are connecting to the databases itself to drop it :)