我目前正在尝试通过以下代码删除数据库
using Microsoft.sqlServer.Management.Smo; var server = new Server(Server); server.KillAllProcesses("Db"); server.KillDatabase("Db");
有时它可以工作,但其他人我得到以下例外:
Microsoft.sqlServer.Management.Smo.FailedOperationException: Kill database Failed for Server ‘Host1’.
—> Microsoft.sqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-sql statement or batch.
—> System.Data.sqlClient.sqlException: Changes to the state or options of database ‘Db’ cannot be made at this time. The database is in single-user mode,and a user is currently connected to it.