0

unfortunately delete F Drive from My pc . here location Sql 2008 R2(main DB) .mdf and .ldf file. anyway I recover with data recovery software All this file same drive and same folder. As like previous.now when I tried Attach my database but it's does't Attach.enter image description here

4
  • how many files are related do this database you're having problems to attach? I ask because the fact that it's a .mdf file doesn't guarantee that it's the main file of the database. It could just be a secondary file created with the .mdf extension.
    – Ronaldo
    Commented Aug 6, 2019 at 16:38
  • nobody .mdf file doesn't Attach.which recover from delete. Commented Aug 7, 2019 at 4:38
  • Ok, since you used a recovery software (and it probably means you don't have an available backup to restore from) you could try using sp_attach_single_file_db although it's not intended for this purpose. Depending on how important was that data for your organization, you could also try something like SysTools SQL Recovey.
    – Ronaldo
    Commented Aug 7, 2019 at 12:33
  • I didn't mention on the previous comment, but the error 5171 seems to be related to corrupted data. The tools I advised you to try I have never used them myself, so you're on your own.
    – Ronaldo
    Commented Aug 7, 2019 at 12:43

1 Answer 1

0

It seems like you are facing issues attaching a recovered SQL Server database after accidentally deleting the F drive from your PC. Here are steps to troubleshoot and resolve the problem:

  1. Check File Permissions:

    • Ensure that the recovered .mdf and .ldf files have the necessary permissions for the SQL Server service account to access them.
  2. Move Files to Original Location:

    • If the recovered files are not already there, move the .mdf and .ldf files to the original location where the SQL Server instance expects to find them.
  3. Update File Paths in SQL Server:

    • If you've moved the files, you may need to update the file paths in SQL Server. Use the SQL Server Management Studio (SSMS) to modify the file paths in the database properties.
  4. Check SQL Server Error Log:

    • Examine the SQL Server error log for any error messages related to the attachment process. It may provide more details on why the attachment is failing.
  5. Use T-SQL for Attach:

    • Instead of using the SQL Server Management Studio GUI, try using T-SQL commands to attach the database. Open a query window and run a command like:
  6. sql

    • CREATE DATABASE YourDatabaseName
      ON (FILENAME = 'Path\To\Your\Database.mdf'),
      (FILENAME = 'Path\To\Your\Database.ldf')
      FOR ATTACH;
      
  7. Check Database Compatibility:

    • Verify that the SQL Server version you are trying to attach the database to is compatible with the version from which the database was backed up.
  8. Check SQL Server Service Account Permissions:

    • Ensure that the SQL Server service account has the necessary permissions to access and read the folder where the .mdf and .ldf files are located.
  9. Check for File Corruption:

    • It's possible that the recovered files may be corrupted. Verify the integrity of the recovered .mdf and .ldf files.
  10. Database Detach and Attach:

    • If you have the original .mdf and .ldf files before deletion, consider detaching the database from SQL Server, copying the files back to their original location, and then attaching the database again.
  11. Seek Professional Assistance:

    • If all else fails, consider seeking assistance from a database administrator or SQL Server expert who may be able to diagnose and resolve the issue more specifically.
1
  • Is this A.I. generated?
    – Dominique
    Commented Nov 29, 2023 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .