Sql server veritabanı kullanan herkesin başına muhakkak gelen bir olaydır, log dosyalarının bozulması . Bu gibi bir durumda log dosyamız olmadan mdf dosyamızı başka bir veritabanına attach etmek sorun olur. Bunun için aşşağıdaki yöntemleri izleyebiliriz.
1.Mdf dosyamızla aynı isimde bir veritabanı yaratıyorız.
2.Sql serverımızı durdurup oluşan mdf dosyasının yerine kendi mdf dosyamızı koyuyoruz.
3.Sql serverımızı başlatıyoruz.
4. Aşşağıdaki scriptleri çalıştırıyoruz
USE [master] GO ALTER DATABASE [DATABASEADI] SET EMERGENCY GO ALTER DATABASE [DATABASEADI] SET SINGLE_USER GO DBCC CHECKDB ([DATABASEADI], REPAIR_ALLOW_DATA_LOSS) GO ALTER DATABASE [DATABASEADI] SET MULTI_USER GO ALTER DATABASE [DATABASEADI] SET ONLINE GO
Sql komutlarını çalıştırdıktan sonra aşşağıdaki gibi hata mesajları alacaksınız.
Msg 5173, Level 16, State 1, Line 1
One or more files do not match the primary file of the database. If you are attempting to attach a database, retry the operation with the correct files. If this is an existing database, the file may be corrupted and should be restored from a backup.
Log file ‘c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS2008\MSSQL\DATA\MyDatabase_log.ldf’ does not match the primary file. It may be from a different database or the log may have been rebuilt previously.
Warning: The log for database ‘MyDatabase’ has been rebuilt. Transactional consistency has been lost. The RESTORE chain was broken, and the server no longer has context on the previous log files, so you will need to know what they were. You should run DBCC CHECKDB to validate physical consistency. The database has been put in dbo-only mode. When you are ready to make the database available for use, you will need to reset database options and delete any extra log files.
DBCC results for ‘MyDatabase’.
Service Broker Msg 9675, State 1: Message Types analyzed: 14.
Service Broker Msg 9676, State 1: Service Contracts analyzed: 6.
Service Broker Msg 9667, State 1: Services analyzed: 3.
Service Broker Msg 9668, State 1: Service Queues analyzed: 3.
Service Broker Msg 9669, State 1: Conversation Endpoints analyzed: 0.
Service Broker Msg 9674, State 1: Conversation Groups analyzed: 0.
Service Broker Msg 9670, State 1: Remote Service Bindings analyzed: 0.
Service Broker Msg 9605, State 1: Conversation Priorities analyzed: 0.
… Long list of GBCC messages …
CHECKDB found 0 allocation errors and 0 consistency errors in database ‘MyDatabase’.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
———————–
Bu hata mesajlarına rağmen veritabanımız şuanda kullanıma hazırdır. Kolay gelsin ![]()
Şuradan alıntıdır.
Mükemmeldi.Denedim oldu.
Olduğuna sevindim . Kolay gelsin.