Fix/Solution/Workaround:
Follow below steps:-
1. Move mdf and ndf files to another directory (Data_old)
2. Create a database with the same name and same file names and locations as the original databases. (this only applies to the mdf and ndf files the log file can go anywhere)
3. Stop the SQL Server service.
4. Overwrite new mdf and ndf files with the original ones.
5. Start SQL Server.
6. Run this script (Set the @DB variable to the name of your database before running):
Declare @DB sysname;
set @DB = ‘DBName’;
– Put the database in emergency mode
EXEC(‘ALTER DATABASE [' + @DB + '] SET EMERGENCY’);
– Set single user mode
exec sp_dboption @DB, ‘single user’, ‘TRUE’;
or
– Repair database
DBCC checkdb (@DB, repair_allow_data_loss);
– Turn off single user mode
exec sp_dboption @DB, ‘single user’, ‘FALSE’;
If you are not able to connect after single user then run below cmd in one go.
Alter database dbname set single_user with roll back immediate
go
Run your DBCC checkdb command
go
Alter database dbname set multi_user
I got an error stating that the log file did not match the data file. You can ignore this as we are rebuilding the log file.
DB研討會 : [教學]MSSQL 2016 的 Transaction Log 檔(ldf)爆炸(或爛掉了)怎麼辦!?
發表者 | 討論內容 |
---|---|
冷日 (冷日) |
發表時間:2016/11/12 7:27 |
![]()
|
|
|
討論串
-
[教學]MSSQL 2016 的 Transaction Log 檔(ldf)爆炸(或爛掉了)怎麼辦!? (冷日
(冷日), 2016/11/12 7:15) -
[轉貼]MSSQL 2016 Set a Database to Single-user Mode (冷日
(冷日), 2016/11/12 7:23) - »
[轉貼]MSSQL 2016 Error Msg 1813 (冷日
(冷日), 2016/11/12 7:27)