title: Issues while extracting data from corrupted database
body: <p>I have a problem with a corrupted database that i need to extract the data from it..</p>
  
  <p>as a start our database server crashed and we extracted the .mdf and .ldf files from the file system but it appears that a specific database “XYZ” was running some operations when the crash happened as when I was trying to attach i got the following error:</p>
  
  <blockquote>
    <p>The log scan number (218:387:1) passed to log scan in database ‘XYZ’
    is not valid</p>
  </blockquote>
  
  <p>so I hack attached it by creating a database with the same name and replaced the .mdf file and delete the new .ldf after stopping SQL SERVER Service to reproduce your scenario, and started it again.</p>
  
  <p>i followed Paul Randal instructions from this <a href="http://www.sqlskills.com/blogs/paul/checkdb-from-every-angle-emergency-mode-repair-the-very-very-last-resort/" rel="nofollow">Link</a> as follows:</p>
  
  <pre><code>ALTER DATABASE [XYZ] SET EMERGENCY;
  GO
  
  ALTER DATABASE [XYZ] SET SINGLE_USER;
  GO
  
  DBCC CHECKDB (N’XYZ’, REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS, NO_INFOMSGS;
  GO
  </code></pre>
  
  <p>but when i ran the DBCC CHECKDB Command i faced the following message</p>
  
  <blockquote>
    <p>File activation failure. The physical file name “E:\Program
    Files\Microsoft SQL
    Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\XYZ_log.ldf” may be
    incorrect. The log cannot be rebuilt because there were open
    transactions/users when the database was shutdown, no checkpoint
    occurred to the database, or the database was read-only. This error
    could occur if the transaction log file was manually deleted or lost
    due to a hardware or environment failure. Msg 5123, Level 16, State 1,
    Line 1 CREATE FILE encountered operating system error 3(failed to
    retrieve text for this error. Reason: 15105) while attempting to open
    or create the physical file ‘C:\Program Files\Microsoft SQL
    Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\XYZ_log.ldf’. Msg 5024, Level
    16, State 2, Line 1 No entry found for the primary log file in
    sysfiles1. Could not rebuild the log. Msg 5028, Level 16, State 2,
    Line 1 The system could not activate enough of the database to rebuild
    the log. File activation failure. The physical file name “E:\Program
    Files\Microsoft SQL
    Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\XYZ_log.ldf” may be
    incorrect. The log cannot be rebuilt because there were open
    transactions/users when the database was shutdown, no checkpoint
    occurred to the database, or the database was read-only. This error
    could occur if the transaction log file was manually deleted or lost
    due to a hardware or environment failure. Msg 5123, Level 16, State 1,
    Line 1 CREATE FILE encountered operating system error 3(failed to
    retrieve text for this error. Reason: 15105) while attempting to open
    or create the physical file ‘C:\Program Files\Microsoft SQL
    Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\XYZ_log.ldf’. Msg 5024, Level
    16, State 2, Line 1 No entry found for the primary log file in
    sysfiles1. Could not rebuild the log. Msg 5028, Level 16, State 2,
    Line 1 The system could not activate enough of the database to rebuild
    the log. Msg 7909, Level 20, State 1, Line 1 The emergency-mode repair
    failed.You must restore from backup.</p>
  </blockquote>
  
  <p>so as a final resort i tried to SELECT INTO each table by itself in a new database, and it worked for 80% percent of the tables but when it comes to a specific table <em>"The most important one"</em> when i tried the SELECT INTO statement i faced the following error:</p>
  
  <blockquote>
    <p>Could not continue scan with NOLOCK due to data movement.</p>
  </blockquote>
  
  <p>is there any solution for that, i got a hint to read each page by itself but I'm not able to find how can this be done.</p>
  
  <p>I'm using SQL Server 2008 R2 btw </p>
  
  <p>Thanks in advance, </p>