A log error is prompted when a database is attached. A solution is always unavailable.

Source: Internet
Author: User

Back up the data file and follow these steps:

1. Create a database with the same name (the data file must be consistent with the original one)

2. Stop SQL server again (do not detach the database)

3. overwrite the new database with the data file of the original database.

4. Restart SQL Server.

5. When you open the Enterprise Manager, there will be a doubt. Ignore it and execute the following statement (note that you must modify the database name)

Use master
Go

Sp_configure 'Allow updates', 1 reconfigure with override
Go

Update sysdatabases set status = 32768 where name = 'suspicious database name'
Go

Sp_dboption 'questionable database name', 'single user', 'true'
Go

DBCC checkdb ('questionable database name ')
Go

Update sysdatabases set status = 28 where name = 'questionable database name'
Go

Sp_configure 'Allow updates', 0 reconfigure with override
Go

Sp_dboption 'questionable database name', 'single user', 'false'
Go

6. After completion, you can access the data in the database. At this time, the database itself is generally still faulty,

After using the above method, the database can be used normally. when the data is imported, the system prompts to avoid the recovery mode or something, and the import is always unsuccessful.

 
The database script creates a new database and imports the data.

The last step is to create a new database and import the records of the problematic database to the new database. The new data is imported to the new database !!

 

 

 

I collected the data at the same time. Haha, it is also good to read more!

 

 

Only the MDF file restoration technology is available.

For various reasons, if we only backed up the MDF file at that time, it would be very troublesome to restore it.
If your MDF file is generated by the current database, you may be lucky to use sp_attach_db or sp_attach_single_file_db to restore the database,
However, a message similar to the following appears.
Device activation error. The physical file name 'C:/program files/Microsoft SQL Server/MSSQL/data/test_log.ldf' may be incorrect.
You have created a new log file named 'C:/program files/Microsoft SQL Server/MSSQL/data/test_log.ldf.
However, if your database files are copied from other computers, the above method may not work. You may get an error message similar to the following.
Server: Message 1813, level 16, status 2, Row 1
Failed to open the new database 'test '. Create database will be terminated.
Device activation error. The physical file name 'd:/test_log.ldf' may be incorrect.

What should we do? Don't worry. The following is an example of the restoration method.
A. We use the default method to create a database for recovery (such as test ). It can be created in SQL Server Enterprise Manager.
B. Stop the database server.
C. Delete the log file test_log.ldf of the database you just generated, and overwrite the generated database data file test_data.mdf with the MDF file to be restored.
D. Start the database server. In this case, the database test status is "Suspect ". At this time, you cannot perform any operations on this database.
E. Set the database to allow direct operation of system tables. In SQL Server Enterprise Manager, right-click the database server and select "properties". On the "Server Settings" Page, select "allow direct modification to system directory. You can also use the following statement.
Use master
Go
Sp_configure 'Allow updates', 1
Go
Reconfigure with override
Go

F. Set test to emergency repair mode.
Update sysdatabases set status =-32768 where dbid = db_id ('test ')
At this time, you can see in SQL Server Enterprise Manager that the database is in "Read-Only/suspicious/offline/emergency mode", you can see the tables in the database, but only the system tables

G. Execute the true recovery operation below to recreate the database log file.
DBCC rebuild_log ('test', 'c:/program files/Microsoft SQL Server/MSSQL/data/test_log.ldf ')
If the following prompt is displayed during execution:
Server: Message 5030, level 16, status 1, Row 1
The database cannot be locked for this operation.
DBCC execution is complete. If DBCC outputs an error message, contact the system administrator. [Brown] [/I]
This indicates that other programs are using this database. If you opened the system table of the test database using SQL Server Enterprise Manager in step f, you can exit SQL Server Enterprise Manager.
The prompt for correct execution should be similar:
Warning: the log of the database 'test' has been rebuilt. Transaction consistency is lost. DBCC checkdb should be run to verify physical consistency. The database must be reset and redundant log files may need to be deleted.
DBCC execution is complete. If DBCC outputs an error message, contact the system administrator.
In SQL Server Enterprise Manager, you can see that the database status is "only for DBO ". Now you can access the user tables in the database.

H. Verify Database Consistency (omitted)
DBCC checkdb ('test ')
The general execution result is as follows:
Checkdb finds 0 allocation errors and 0 consistency errors (in the database 'test ).
DBCC execution is complete. If DBCC outputs an error message, contact the system administrator.

I. Set the database to normal
Sp_dboption 'test', 'dbo use only', 'false'
If no error occurs, Congratulations. Now we can use the recovered database normally.

J. In the last step, we need to restore the "allow direct modification to the system directory" set in Step E. It is dangerous to directly operate system tables. Of course, we can recover the data in SQL Server Enterprise Manager or use the following statement.
Sp_configure 'Allow updates', 0
Go
Reconfigure with override

 

 

 

 

 

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.