Restore database with Attach

  • Hi,

    I get from client base in .mdf and .ldf
    I try to restore this base in my SQL but I have error... 
    Someone can help me, how can I correct restore this base?
    My knowledge SQL is small and I need help.

    Error:
    Msg 1802, Level 16, State 7, Line 3
    CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
    Msg 824, Level 24, State 6, Line 3
    SQL Server detected a logical consistency-based I/O error: torn page (expected signature: 0xffffffff; actual signature: 0xf8ae914f). It occurred during a read of page (0:0) in database ID 0 at offset 0000000000000000 in file 'B:\Odzyskane\pse_base_log.ldf'. Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.

  • Did you do what it suggested in the error message?  Did your client gracefully shut down SQL Server or detach the database before sending you the files?  Do you have the option to ask your client to back up the database and send you the .BAK file?

    John

  • My client can't give me database in .bak beacouse he was attacked and have encrypted all files... He restore only this files from 02.01.2018

    Marcin

  • John Mitchell-245523 - Friday, February 9, 2018 2:35 AM

    Did you do what it suggested in the error message?  

    I try use this, but SQL [Could not find stored procedure 'sp_dboption']
    use master 
    declare @databasename varchar(255)
    set @databasename='MyDatabase.mdf'
    exec sp_dboption @databasename, N'single', N'true' 
    dbcc checkdb(@databasename,REPAIR_ALLOW_DATA_LOSS)
    dbcc checkdb(@databasename,REPAIR_REBUILD)
    exec sp_dboption @databasename, N'single', N'false' 

  • Where did you get that code?!

    Actually, if you can't even restore the database, you've nothing to run a DBCC check against.  Is the client saying that they've never backed up the database in the past, or if they have, that all their backup files were destroyed in what I assume was a ransomware attack?  If that's the case, the best you can do may be to advise your client to make sure that backups are moved off site as early and as frequently as possible.

    John

  • Here I get this code: https://www.datanumen.com/sql-recovery/articles/dbcc-checkdb.htm

    Yes, client never backed up the database, and yes all files was destroyed by a ransomware attack.

    So it is not possible to repair this database?

  • Not sure when that was published, but I suspect it's very out of date.  sp_dboption is deprecated: you should use ALTER DATABASE these days.

    I'm not looking over your shoulder, so I can't see what you see, but I suspect that the database is indeed not recoverable.  How are you attempting to attach the database and at what point do you get the error?

    John

  • I use this instructions https://docs.microsoft.com/en-us/sql/relational-databases/databases/attach-a-database

    When I click extract(query) or when I use function attach database I see this:

    ===================================

    Attach database failed for Server '.\SQL'. (Microsoft.SqlServer.Smo)

    ------------------------------
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=14.0.17213.0+((SSMS_Rel).171128-2020)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476

    ------------------------------
    Program Location:

     at Microsoft.SqlServer.Management.Smo.Server.AttachDatabase(String name, StringCollection files)
     at Microsoft.SqlServer.Management.SqlManagerUI.AttachDatabaseData.PrimaryFile.Attach()
     at Microsoft.SqlServer.Management.SqlManagerUI.AttachDatabase.SendDataToServer()

    ===================================

    An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

    ------------------------------
    Program Location:

     at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
     at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType, Boolean retry)
     at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries, Boolean retry)
     at Microsoft.SqlServer.Management.Smo.Server.AttachDatabaseWorker(String name, StringCollection files, String owner, AttachOptions attachOptions)
     at Microsoft.SqlServer.Management.Smo.Server.AttachDatabase(String name, StringCollection files)

    ===================================

    SQL Server detected a logical consistency-based I/O error: torn page (expected signature: 0xffffffff; actual signature: 0xf8ae914f). It occurred during a read of page (0:0) in database ID 0 at offset 0000000000000000 in file 'B:\Odzyskane\pse_base_log.ldf'. Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.
    CREATE DATABASE failed. Some file names listed could not be created. Check related errors. (.Net SqlClient Data Provider)

    ------------------------------
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=824&LinkId=20476

    ------------------------------
    Server Name: .\SQL
    Error Number: 824
    Severity: 24
    State: 6
    Line Number: 1

    ------------------------------
    Program Location:

     at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
     at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)

  • OK, if you can't even attach the database, that limits your options severely.  The only thing I can think of is to pay lots of money to a company that specialises in data recovery and see whether they can get it back for you.  Maybe someone who knows more about corruption than I do will chip in with some advice.

    John

  • Yup, I'll chip in with advice:

    Ask the client to hunt and see if he has any backups from before he got hit with a ransomware attack, because that file is not attachable. I suspect it too is encrypted and hence unreadable.
    Or pay the ransom and hope he gets the key.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I noticed the error message shows problem in log file, rather than data file. If it's not encrypted, but a log corruption, you can try ATTACH_REBUILD_LOG.

    GASQL.com - Focus on Database and Cloud

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply