DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Building a Database Written in Node.js From the Ground Up
  • SQL Recovery Model: Simple vs. Full
  • How to Restore a Transaction Log Backup in SQL Server
  • How to Attach SQL Database Without a Transaction Log File

Trending

  • Integration Isn’t a Task — It’s an Architectural Discipline
  • Next-Gen IoT Performance Depends on Advanced Power Management ICs
  • Go 1.24+ Native FIPS Support for Easier Compliance
  • Role of Cloud Architecture in Conversational AI
  1. DZone
  2. Data Engineering
  3. Databases
  4. How To Recover SQL Server FILESTREAM Enabled Database

How To Recover SQL Server FILESTREAM Enabled Database

In this article, we will discuss three separate methods of how to recover SQL Server FILESTREAM in a database in the case of severe database corruption.

By 
Daniel Calbimonte user avatar
Daniel Calbimonte
·
Apr. 26, 21 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
8.1K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

Besides storing table-based data in SQL Server, you can also store Binary Large Object (BLOB) data as files using the SQL Server FILESTREAM feature. This feature allows the storing of the varbinary(max) objects onto the file system instead of placing them inside a database. However, you can create a database with a 'FILESTREAM' filegroup, allowing you to perform actions on the data stored in the file system using the database.

Sometimes, when saving files to a database using FILESTREAM in SQL Server, the files may turn corrupt. Also, modifying or deleting the files placed in the file system folder (as FILESTREAM data container) may result in consistency errors reported by DBCC CHECKDB. To fix the errors, you can try restoring the database to its original state. But if the backup is not available, repairing the FILESTREAM database using the DBCC CHECKDB command with the REPAIR_ALLOW_DATA_LOSS option may help.

This article discusses the methods to perform SQL Server FILESTREAM database recovery. It also advises an alternate solution to restore the FILESTREAM database when the backup or restore process fails to fix the issue.

Methods To Recover FILESTREAM Database in SQL Server

Following are the methods you can use to recover the FILESTREAM database in SQL Server:

Method 1: Restore Database From Backup

If you have an updated backup of your FILESTREAM database, restore the database to another location. And then, replace the problematic file in the FILESTREAM container with the file found after restoring the backup. Here’s how you can do this:

  • In SSMS, locate the database you want to restore and right-click on it, and then click Tasks >Restore > Database.

Note: Here, we are explaining steps to restore a complete database backup. However, you can also try restoring files and filegroup backup.

Restore Database...

  • In the ‘Restore Database’ wizard, perform these steps:
    • Under Source, select the Device option and click the Browse (…) button next to it.Device option and click Browse
    • Click Add in Select backup devices dialog box.Click Add in Select backup Devices
    • Select the FILESTREAM database backup file (in our case FILESTREAMTestDB.bak file) and click OK.Filestream database backup file
  • The path of the FILESTREAM database backup file will be added in the Backup media section. Click OK.Select backup devices
  • The database backup file location and the database name will be displayed in the ‘Restore Database’ wizard.FILESTREAMTestDB highlighted in the wizard

  • Next, click the Files tab under Select a page from the left side menu. In the window that opens, change the location of the data file and log file folders of the source database, as the restored database should be not be added into a similar location as the original DB having the same file names.Data and log file folder

  • Click OK. The database will be restored and saved in the specified location.
  • Now, navigate to the location of the FILESTREAM container in SQL Server where the newly restored database is saved.
  • Once you have found the corrupted or missing file by restoring the backup, you can copy the restored database file into the FILESTREAM container.

Method 2: Run DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS

If the backup for the FILESTREAM database is not available or you can’t find the file in the backup, you can recover the FILESTREAM database by executing the DBCC CHECKDB command with ‘REPAIR_ALLOW_DATA_LOSS’. Doing so will fix corruption in the file stored in the FILESTREAM container.

Follow these steps to repair the corrupt FILESTREAM database:

  • Put the SQL database in single-user mode by running the following command:
SQL
 




x


 
1
ALTER DATABASE FILESTREAMTestDB_test SET SINGLE_USER WITH ROLLBACK IMMEDIATE 
2

          
3
GO



The above command will kill any active connection in the database and put the database in single-user mode.

  • Now, try to repair the database by using the below command:
SQL
 




xxxxxxxxxx
1


 
1
DBCC CHECKDB('FILESTREAMTestDB_test', REPAIR_ALLOW_DATA_LOSS)



Running this command will delete the row containing the FILESTREAM file and fix consistency errors.

  • Set the database to ‘MULTI_USER’ mode by executing the following command:
SQL
 




xxxxxxxxxx
1


 
1
ALTER DATABASE FileStreamDemoDB_test SET MULTI_USER
2

          
3
 GO



You will now be able to access your database.

Method 3: Use SQL Recovery Tool

If none of the above methods works for you, try using a SQL recovery tool such as Stellar Repair for MS SQL to restore the FILESTREAM database. Such a tool helps you select a corrupt database file (.mdf/.ndf), repair it, and recover all the data types.

Conclusion

If you are experiencing issues with your SQL Server FILESTREAM enabled database, such as database corruption, inaccessible files, etc. you can try the methods discussed in this post to recover the FILESTREAM database. You can try restoring the database from backup and replace the corrupt or missing file (in the FILESTREAM container) with the file you have found after restoring the backup. If you don’t have a backup, run the DBCC CHECKDB command with the repair option. But if nothing works, using a SQL recovery tool can come in handy.

Database sql File system Data file

Opinions expressed by DZone contributors are their own.

Related

  • Building a Database Written in Node.js From the Ground Up
  • SQL Recovery Model: Simple vs. Full
  • How to Restore a Transaction Log Backup in SQL Server
  • How to Attach SQL Database Without a Transaction Log File

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!