How to solve MSSQL2012 attaching database 5173, errors

Source: Internet
Author: User
When you add a ms SQL SERVER database, you may encounter errors of 9003 or 9004, which are usually caused by mismatch between log files and data files. It is best to restore the backup file directly with backup. If there is no backup, it is still relatively simple to solve this problem. This method also applies to databases with no log files attached.

 

 

The general idea is:

 


  1. Create a database with the same name

  2. Stop SQL service

  3. Overwrite the MDF file, delete the log file, and then start the SQL service

  4. Change the database from challenge mode to single-user emergency mode

  5. Fix DBCC CHECKDB

 

The following describes the specific operation details. Steps 1st, 2, and 3 do not need to be said. Starting from Step 4, we assume that an error is reported when a database named testdb is attached.

 

Step 3: overwrite the file. After the SQL service is restarted, the database will be in the "questionable" status. Create a new query and execute the following SQL statement,

USE MASTER
GO
Exec sp_configure 'allow updates', 1
GO
Reconfigure with override
GO
Alter database testdb
SET SINGLE_USER
With rollback immediate;
GO
Alter databas 'testdb' SET EMERGENCY
GO

After the execution is complete, run the following query to restore the database:

Dbcc checkdb ('testdb', REPAIR_ALLOW_DATA_LOSS)

Then execute the following SQL statement to bring the database online.


Alter database testdb
SET MULTI_USER
With rollback immediate;
GO
Alter database testdb SET ONLINE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.