Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ProEdge
Yak Posting Veteran
64 Posts |
Posted - 2007-04-09 : 15:52:18
|
Hi everyone, we had a power spike over the weekend and it looks like one of our databases went bad. It appears the log file got corrupted (probably during replication) and now it's passing the message "The LSN (9481791:16:19) passed to log scan in database 'myDatabase' is invalid." So what I'm trying to do now is use the system stored procedure 'sp_attach_single_file_db'. My syntax is:sp_attach_single_file_db @dbname = 'myDatabase', @physname = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\myDatabase_Data.mdf' According to BOL, the procedure builds a new log file for you. However, when I run this, it returns the original message I mentioned above. I also tried moving the current ldf file out of the directory and when I run it again, it returns: Server: Msg 1813, Level 16, State 2, Line 1Could not open new database 'myDatabase'. CREATE DATABASE is aborted.Device activation error. The physical file name 'C:\Program Files\Microsoft SQL Server\MSSQL\data\myDatabase.ldf' may be incorrect.Anyone know what's going on? |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-04-09 : 16:08:40
|
It works only when the db is closed properly, you may need restore from good backup in this case. |
 |
|
ProEdge
Yak Posting Veteran
64 Posts |
Posted - 2007-04-09 : 16:09:52
|
quote: Originally posted by rmiao It works only when the db is closed properly, you may need restore from good backup in this case.
That's not what I've read though. The mdf file is good but the ldf is bad. So I thought I could rebuild the ldf using this. |
 |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-04-09 : 16:18:53
|
Rebuilding log is different process, here are steps:Steps to recover db without log file:--1. Create DatabaseUSE masterGOCREATE DATABASE mydatabaseON PRIMARY ( NAME = mydatabase_data,FILENAME = 'c:\mydatabase.mdf',SIZE = 2MB,MAXSIZE = 10,FILEGROWTH = 1)LOG ON ( NAME = mydatabase_Log1,FILENAME = 'c:\mydatabase1.ldf',SIZE = 1MB,MAXSIZE = 10, FILEGROWTH = 1),( NAME = mydatabase_Log2,FILENAME = 'c:\mydatabase2.ldf',SIZE = 1MB,MAXSIZE = 10, FILEGROWTH = 1)GO--2. Add datause mydatabasegocreate table x123(id int)insert into x123 select 111223insert into x123 select 111223insert into x123 select 111223insert into x123 select 111223insert into x123 select 111223--3. Detach Databaseuse mastergosp_detach_db mydatabase--4. Accidental Deletetion. Delete mydatabase1.ldf and delete mydatabase2.ldf--5. Try to attach mydatabase.mdfsp_attach_db 'mydatabase','c:\mydatabase.mdf'Error message:Server: Msg 1813, Level 16, State 2, Line 1Could not open new database 'mydatabase'. CREATE DATABASE is aborted.Device activation error. The physical file name 'c:\mydatabase1.ldf' may be incorrect.Device activation error. The physical file name 'c:\mydatabase2.ldf' may be incorrect.--6. Rename c:\mydatabase.mdf to MydatabaseXXXXXX.mdf--7. Create database mydatabaseUSE masterGOCREATE DATABASE mydatabaseON PRIMARY ( NAME = mydatabase_data,FILENAME = 'c:\mydatabase.mdf',SIZE = 2MB,MAXSIZE = 10,FILEGROWTH = 1)LOG ON ( NAME = mydatabase_Log1,FILENAME = 'c:\mydatabase1.ldf',SIZE = 1MB,MAXSIZE = 10, FILEGROWTH = 1),( NAME = mydatabase_Log2,FILENAME = 'c:\mydatabase2.ldf',SIZE = 1MB,MAXSIZE = 10, FILEGROWTH = 1)GO--8 Stop SQL Server--9 Delete mydatabase.mdf --10 rename MydatabaseXXXXXX.mdf to mydatabase.mdf --11 Start SQL Server service--12 run the followinguse Mastergosp_configure "allow", 1goreconfigure with overridego--13update sysdatabases set status = 32768 where name = 'Mydatabase'gocheckpointgoshutdown with nowaitgo--14. delete mydatabase1.ldf and mydatabase2.ldf--15. run this querydbcc traceon(3604)--16. rebuild Logdbcc rebuild_log('Mydatabase','c:\Mydatabase1.ldf')--17. update sysdatabases set status = 0 where name = 'mydatabase'--18. restart sql server--19. run the following queryuse mydatabasegodbcc checkdb godbcc checkallocgobackup database mydatabase to disk = 'c:\mydatabase.bak'goselect * from x123go |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-04-10 : 01:44:44
|
Do you need "checkalloc" as well as "checkdb"?"backup database mydatabase ..." Kristen |
 |
|
brahianblade11
Starting Member
1 Post |
Posted - 2011-11-28 : 18:55:50
|
this topic was help full for me. Thanks rmiao. I do all the step and all work property. tanks..........Brahian Pena |
 |
|
|
|
|
|
|