简体   繁体   English

如何在没有index.idx文件的情况下附加SQL Server 2008 R2中的数据库

[英]How to attach database in SQL Server 2008 R2 without index.idx file

I have a database test ( test.mdf , test_ldf.log and test_idx.idx ). 我有一个数据库测试( test.mdftest_ldf.logtest_idx.idx )。 By mistake I deleted the test_idx.idx file and due to file was over 20 GB. 我误删了test_idx.idx文件,由于文件超过20 GB。

I have used all type of recovery software but can't find the file. 我使用了所有类型的恢复软件,但找不到该文件。

Unfortunately that database is not backed up, and now SQL Server 2008 R2 doesn't let me attach the database. 不幸的是,该数据库没有备份,现在SQL Server 2008 R2不允许我附加数据库。

Is there any way to attach the database test.mdf file without index file? 有没有办法附上没有索引文件的数据库test.mdf文件?

Error when I try to attach database: 当我尝试附加数据库时出错:

Unable to open the physical file ".idx". 无法打开物理文件“ .idx”。 Operating system error 2: "2(failed to retrieve text for this error. Reason: 15105)". 操作系统错误2:“ 2(由于该错误而无法检索文本。原因:15105)”。 (Microsoft SQL Server, Error: 5120) (Microsoft SQL Server,错误:5120)

  1. create a dummy database (name is not important) with the same file structures. 创建具有相同文件结构的虚拟数据库(名称不重要)。 ie a data file, log file and index file. 即数据文件,日志文件和索引文件。

  2. take the index file and database offline like so: 使索引文件和数据库脱机,如下所示:

    alter database <dbname> modify file(name = '<name of your index file>', offline) 更改数据库<dbname>修改文件(名称='<索引文件的名称>',脱机)

    alter database <dbname> set offline 更改数据库<dbname>设置为脱机

You'll not be able to recover the offline file (to my knowledge) so dont give it the same logical name as your original file - you'll see why in a moment. (据我所知)您将无法恢复脱机文件,因此请不要使用与原始文件相同的逻辑名称-稍后您会看到原因。

  1. now overwrite the dummy database files with what you have left of your broken database (obviously keep the copies somewhere safe!) 现在,用损坏的数据库中剩下的内容覆盖虚拟数据库文件(显然,将副本保存在安全的地方!)

  2. bring the database back online 使数据库重新联机

    alter database <dbname> set online 联机设置alter database <dbname>

At this point your data should be accessible. 此时,您的数据应该可以访问了。

  1. create new filegroup/file with the same logical names as your original and rebuild indexes 使用与原始逻辑名称相同的逻辑名称创建新的文件组/文件并重建索引

Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM