How to Fix SQL Server Error 7905 (Msg 7905)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see sql server error 7905 when an unexpected folder sits inside a FILESTREAM container. To fix it, move the unauthorized folder out of the container path and run a database check. The database engine manages FILESTREAM storage folders on the host file system. When a person or external tool adds a folder inside that path, consistency checks fail. You must clean up the host file system to clear the error. What causes sql server error 7905 in the database engine In Microsoft SQL Server, mes

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 see sql server error 7905 when an unexpected folder sits inside a FILESTREAM container. To fix it, move the unauthorized folder out of the container path and run a database check.

The database engine manages FILESTREAM storage folders on the host file system. When a person or external tool adds a folder inside that path, consistency checks fail. You must clean up the host file system to clear the error.

What causes sql server error 7905 in the database engine

In Microsoft SQL Server, message 7905 carries a severity level of 16. The message states that a directory is not a valid FILESTREAM directory in the container. Each container maps to a specific folder on the storage volume.

The database engine expects total control over the structure of this storage container. It creates internal folders to track tables, partitions, and binary data files. If anything else creates a folder in that tree, the engine flags a corruption risk.

Common triggers include manual file copies, stray backup scripts, or anti-virus quarantine folders. Sometimes an admin creates a temp folder inside the data path by mistake. Storage migration tools can also leave behind tracking folders during a volume move.

During a database consistency check, the engine scans every folder in the container ID. It compares the disk folders against its internal system metadata tables. When a disk folder has no matching metadata record, message 7905 appears in the log.

How to diagnose and fix the failure in production

First, read the exact error message text to find the folder name and container ID. Do not delete the folder right away, even if it looks empty. Make sure the folder does not hold valid files moved there by mistake.

Look at the creation date and file owner of the unexpected folder on disk. This step shows which OS account or background tool created the bad directory. Move the stray folder to a safe backup location outside the FILESTREAM tree.

After you move the folder, run a database check to confirm the fix. Avoid granting broad roles when engineers inspect the database during this process. In SQL Server, the db_owner role can drop the database and run all maintenance tasks.

Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Most engineers who investigate logs only need to read user tables and views. The db_datareader fixed role lets members read all data from all user tables and views. Note that you cannot change the permissions assigned to fixed database roles.

For people who access many databases on an instance, a login in master is common. For access to one or a few databases, a contained database user is an option. An admin must first enable contained databases on the server and the database.

How to prevent stray folders in FILESTREAM containers

Lock down Windows file system permissions on all FILESTREAM root folders right away. Only the database service account should have write access to those disk directories. Remove human user accounts from the folder access list on the storage host.

Update your anti-virus rules to skip scanning inside active FILESTREAM container paths. Security tools often drop quarantine or metadata folders into the directories they scan. Configure storage backup agents so they do not write state folders inside data volumes.

Review your database roles to keep day-to-day access tight as well. Remember that all database roles, including public, have the connect permission by default. If a user must never read table data, the db_denydatareader role blocks all reads.

Similarly, the db_denydatawriter role stops a user from adding, changing, or deleting table data. Keep OS admin accounts separate from daily database user accounts across your team. This separation stops accidental file drops during routine database queries and checks.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

Does sql server error 7905 mean my database data is lost?

No, this error usually means an extra folder exists on the disk. Your actual table rows and valid FILESTREAM files remain intact if you move the stray folder.

Can I fix message 7905 by running a repair command that allows data loss?

You should avoid destructive repair commands for this specific directory error. Moving the invalid folder out of the container path on the OS disk resolves the issue safely.

What role should an engineer use to check table records after the fix?

Assign the db_datareader fixed database role so the user can read all user tables and views. Do not grant db_owner just to verify data, since db_owner allows full maintenance and dropping the database.

The query runs. The emails stay hidden.