How to Fix SQL Server Error 7931 (Msg 7931)
You get sql server error 7931 when the database engine sees a duplicate FILESTREAM directory ID. You can fix it by restoring from a clean backup or repairing the corrupted partition. This failure returns message 7931 with severity level 16 during database consistency checks. The exact alert states that a FILESTREAM directory ID for a partition was seen two times. Severity 16 means the error blocks the current task and needs a person to step in. What causes sql server error 7931 in the databas
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You get sql server error 7931 when the database engine sees a duplicate FILESTREAM directory ID. You can fix it by restoring from a clean backup or repairing the corrupted partition.
This failure returns message 7931 with severity level 16 during database consistency checks. The exact alert states that a FILESTREAM directory ID for a partition was seen two times. Severity 16 means the error blocks the current task and needs a person to step in.
What causes sql server error 7931 in the database engine
SQL Server uses the FILESTREAM feature to store binary files on the file system. The database engine keeps track of these files using unique directory IDs for each partition. Each partition must point to one unique folder path on the storage drive.
Msg 7931 fires when the internal metadata tables list the same directory ID twice. This duplicate record breaks the one-to-one link between the database table and the disk folder. When you run a database check, the engine spots the duplicate ID and stops.
Storage failures, sudden power loss, or bad disk drivers often cause this metadata mismatch. A failed file system restore or manual changes to the storage folders can also trigger it. If someone copies a folder by hand, the engine gets confused during the next scan.
How to diagnose and fix the failure in production
Start by reading the full error log to find the exact partition ID involved. Look for any disk alerts or system crashes that happened right before the error started. Never touch or delete files inside the FILESTREAM folders by hand on the host drive.
The safest way to fix this error is to restore from a known good backup. Make sure your backup includes both the relational database files and the associated file containers. Test the restored copy in a staging setup before you swap it into production.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
If you do not have a clean backup, you may need to export the good rows. Move the readable data into a fresh table and drop the broken partition afterward. Only run repair tools as a last resort because they can delete damaged data rows.
Managing database roles during recovery work
During an outage, teams often grant broad permissions so engineers can check the broken tables. Giving out the db_owner fixed role is risky because members can drop the entire database. You cannot change the permissions assigned to fixed database roles in SQL Server.
Instead, give investigating engineers read access by adding them to the db_datareader role. Members of db_datareader can read all data from all user tables and views. If a user only needs access to one database, consider a contained database user.
A contained user has a password and is not tied to a login in master. An admin must enable contained databases on the server and the database first. For sensitive tables, data masking rewrites matched fields like emails or card numbers in results.
Govern SQL Server queries and responses in flight
Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.
With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.
Frequently asked questions
What does severity 16 mean for message 7931?
Severity 16 shows a general error that the user or admin must fix. It stops the current check or query, though the whole server stays online.
Can I fix Msg 7931 by deleting the duplicate folder on disk?
No, deleting files or folders on disk makes the metadata corruption much worse. Always use database restore workflows or table rebuilds to clean up duplicate directory IDs.
Which role should engineers use to inspect affected user tables?
Use the db_datareader fixed role so engineers can read user tables without changing data. Avoid using db_owner or db_datawriter unless the person is actively running the final repair.
Related guides
In this post