[英]Windows: Cannot delete myDB.mdf because the file is open in System
This is the strangest thing ever. 这是有史以来最奇怪的事情。 My company's product uses a database file with Microsoft SQL Server 2008 R2, let's just say it's named
myDB.mdf
. 我公司的产品使用带有Microsoft SQL Server 2008 R2的数据库文件,我们只说它名为
myDB.mdf
。 I want to delete that file and replace it with a same-named database from another system. 我想删除该文件,并用另一个系统中的同名数据库替换它。 So I try to delete it, and of course I can't because it's in use by some process.
因此,我尝试将其删除,但是由于某些进程正在使用它,我当然不能删除它。 I reboot specifically to ensure that nothing's still running that has that file open, and I still can't delete it (same reason).
我专门重新启动以确保打开该文件的所有文件仍在运行,并且我仍然无法删除它(同样的原因)。 I fire up Sysinternals ProcessExplorer and Find->Find Handle or DLL and enter the filename.
我启动Sysinternals ProcessExplorer并找到->查找句柄或DLL,然后输入文件名。 The process that has it open is named 'System' and has a PID of 4. So I go to Control Panel -> Programs and Features and one-by-one, uninstall all of the components of Microsoft SQL Server 2008 R2.
打开它的进程名为“ System”,PID为4。因此,我转到“控制面板”->“程序和功能”,然后一步一步地卸载Microsoft SQL Server 2008 R2的所有组件。 Still can't delete it.
仍然无法删除它。 Oh, I have MS SQL Server 2012 installed... maybe that's it.
哦,我已经安装了MS SQL Server 2012 ...也许就是这样。 Uninstall all components of that.
卸载其中的所有组件。 And some other SQL thing from Microsoft, uninstall that too.
还有Microsoft的其他一些SQL东西,也请卸载它。 Still can't delete it.
仍然无法删除它。 Reboot.
重启。 Don't open ANYTHING, and still can't delete it.
不要打开任何东西,仍然无法删除它。 It gives the error "File In Use: The action can't be completed because the file is open in System. Close the file and try again. [Try Again] [Cancel]".
它给出错误“正在使用文件:由于在系统中打开了文件,因此无法完成操作。关闭文件,然后重试。[重试] [取消]”。 I opened up Control Panel -> Programs and Features again, and confirmed that there are no remaining SQL-ish things.
我再次打开“控制面板”->“程序和功能”,并确认没有SQL残留的东西。 And the file's icon is now a white sheet of paper with the top right edge folded over (ie it has no file association).
文件的图标现在是一张白纸,右上角折叠了(即没有文件关联)。
Any idea how I can make 'System' not open the file so I can delete it? 知道如何使“系统”无法打开文件,以便将其删除吗?
The correct action was to right-click on the database in SQL Management Studio and choose Delete. 正确的操作是右键单击SQL Management Studio中的数据库,然后选择“删除”。 Undoing the steps you've taken may be very difficult.
撤消已采取的步骤可能非常困难。 I'm assuming/hoping this is a dev server.
我假设/希望这是一个开发服务器。 Can you revert to snapshot or nuke the server and install on another?
您可以还原到快照或核对服务器并在另一台服务器上安装吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.