SQL Server 告诉我数据库正在使用,但实际上并未使用
当我尝试删除或恢复数据库时,SQL Server 不断告诉我数据库正在使用中,但当我运行此元数据查询时:
select * from sys.sysprocesses
where dbid
in (select database_id from sys.databases where name = 'NameOfDb')
它什么也不返回。
有时它会返回 1 个进程,该进程是 CHECKPOINT_QUEUE 等待类型。如果我尝试杀死该进程,它不会让我(无法杀死非用户进程)。
有人知道出了什么问题吗?
SQL Server keeps telling me a database is in use when I try to drop it or restore it, but when I run this metadata query:
select * from sys.sysprocesses
where dbid
in (select database_id from sys.databases where name = 'NameOfDb')
It returns nothing.
Sometimes it will return 1 process which is a CHECKPOINT_QUEUE waittype. If I try to kill that process, it won't let me (cannot kill a non-user process).
Anyone have any idea what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我喜欢这个剧本。不要与杀戮斗争..
i like this script. Do not struggle with killing..
尝试从备份恢复数据库时我遇到了同样的问题。我的解决方案是确保在进行还原之前在“选项”页面中选中“覆盖现有数据库(替换)”和“关闭与目标数据库的现有连接”。下面是一个屏幕截图。
I was having the same issue when trying to restore a database from a backup. The solution for me was to ensure that I checked "Overrite the existing database(WITH REPLACE)" and "Close existing connections to destination database" in the Options page BEFORE doing the restore. Here is a screenshot below.
可能有很多东西阻塞了您的数据库。例如,如果您在该数据库上打开了一个查询窗口,它将被您锁定。不包括外部访问,例如 IIS 上的 Web 应用程序。
如果您确实想强制删除它,请选中关闭现有连接选项或尝试手动停止 SQL Server 的服务。
There could be lots of things blocking your database. For example, if you have a query window opened on that database, it would be locked by you. Not counting external accesses, like a web application on IIS.
If you really wanna force the drop on it, check the close existing connections option or try to manually stop SQL Server's service.