From: bin on 6 Apr 2010 05:45 i wrote a program with C# to attach database in windows 7, but i get the error message: "the log cannot be rebuilt because the database was not cleanly shut down" following is the SQL statement sp_attach_single_file_db @dbname = 'Test',@physname = 'c:\temp\test.mdf'
From: Uri Dimant on 6 Apr 2010 06:54 Hi I think the best solution would to restore the database from the last good backup See some workaround (worked for me on SQL 7/2000) 1. From a query window, set the status so that you can update the system tables by running the following query: use Master go sp_configure "allow", 1 go reconfigure with override go 2. Go into the data directory (MSSQL\DATA) and rename the log file associated the DB in question (XXXX.ldf) to some temporary name, such as XXXX.TMP. 3. Exit the query window. 4. Then start up SQL Server from a DOS command window by issuing: sqlservr -c -T3608 -T4022. 5. Bring up another query window and verify that the DB is in emergency mode by issuing: select Name, Status from Sysdatabases where name = '<DB_Name>' 6. Verify that the status is 32768. If it is, then issue the query: dbcc traceon(3604) dbcc rebuild_log('<DB_Name>','<log_filename>') <--- You will need the quotation marks REBUILD_LOG should take less than 5 minutes even on a very large database. It should complete with the message DBCC execution completed 7. Take the database out of bypass recovery mode by issuing the command update sysdatabases set status = 0 where name = '<DBName>' 8. Exit the query window and then shutdown (Ctrl-C in the DOS window) and restart SQL server. Verify the status of the database by running DBCC CHECKDB on the database. "bin" <bin(a)discussions.microsoft.com> wrote in message news:64A50FCC-FEC6-4433-A95B-25407AF4F4DE(a)microsoft.com... >i wrote a program with C# to attach database in windows 7, but i get the > error message: > "the log cannot be rebuilt because the database was not cleanly shut down" > following is the SQL statement > sp_attach_single_file_db @dbname = 'Test',@physname = 'c:\temp\test.mdf' >
From: Dan Guzman on 6 Apr 2010 08:00 > "the log cannot be rebuilt because the database was not cleanly shut down" > following is the SQL statement > sp_attach_single_file_db @dbname = 'Test',@physname = 'c:\temp\test.mdf' Was the database first detached from the source using sp_detach_db? Be aware that the attach might not work if the database was not cleanly detached, although you will often get lucky with files that were only copied. Also, sp_attach_db is deprecated; it is better to use CREATE DATABASE...FOR ATTACH instead. -- Hope this helps. Dan Guzman SQL Server MVP http://weblogs.sqlteam.com/dang/ "bin" <bin(a)discussions.microsoft.com> wrote in message news:64A50FCC-FEC6-4433-A95B-25407AF4F4DE(a)microsoft.com... > i wrote a program with C# to attach database in windows 7, but i get the > error message: > "the log cannot be rebuilt because the database was not cleanly shut down" > following is the SQL statement > sp_attach_single_file_db @dbname = 'Test',@physname = 'c:\temp\test.mdf' >
|
Pages: 1 Prev: Read file info using SMO locks database! Next: SSRS 2008 |