删除.ldf文件后恢复数据库。

时间:2021-09-14 21:42:28

I have deleted the .ldf file. But after that I am unable to recover database. I have tried to detach and attach database but it is throwing exception.

我已经删除了。ldf文件。但之后我无法恢复数据库。我试图分离和附加数据库,但它抛出异常。

“The database [dbName] is not accessible. (ObjectExplorer)”

“数据库[dbName]不可访问。(ObjectExplorer)”

I have also tried to create a new .ldf file with 0 byte size but database recovery fails. There is no backup file for database.

我还尝试创建一个新的0字节大小的.ldf文件,但是数据库恢复失败。数据库没有备份文件。

I have gone through a post The database [dbName] is not accessible. (ObjectExplorer) But this is related to permission where as my issue is related to deletion of .ldf file.

我看过一个帖子,数据库[dbName]是不可访问的。(ObjectExplorer)但这与权限有关,因为我的问题与删除.ldf文件有关。

I do not need log file. I just want to recover my data. Transaction log is not important for me.

我不需要日志文件。我只是想恢复我的数据。事务日志对我来说并不重要。

When I deleted .ldf file SQL server was running. I didn't stopped it at that time.Later I had restarted it.

当我删除.ldf文件时,SQL server正在运行。我当时没有停止。后来我又重新开始了。

1 个解决方案

#1


5  

Suppose if your database name is xyz, then run following command:

假设您的数据库名称是xyz,那么运行以下命令:

ALTER DATABASE xyz REBUILD LOG ON ( NAME = xyz_log, FILENAME ='c:\.....\xyz_log.ldf');
DBCC CHECKDB (xyz);
ALTER DATABASE xyz SET SINGLE_USER;
DBCC CHECKDB (xyz, REPAIR_ALLOW_DATA_LOSS);
ALTER DATABASE xyz SET MULTI_USER;

You may lose some data. This command doesn’t guaranteed full recovery.

你可能会丢失一些数据。此命令不能保证完全恢复。

#1


5  

Suppose if your database name is xyz, then run following command:

假设您的数据库名称是xyz,那么运行以下命令:

ALTER DATABASE xyz REBUILD LOG ON ( NAME = xyz_log, FILENAME ='c:\.....\xyz_log.ldf');
DBCC CHECKDB (xyz);
ALTER DATABASE xyz SET SINGLE_USER;
DBCC CHECKDB (xyz, REPAIR_ALLOW_DATA_LOSS);
ALTER DATABASE xyz SET MULTI_USER;

You may lose some data. This command doesn’t guaranteed full recovery.

你可能会丢失一些数据。此命令不能保证完全恢复。