How to fix Error 9236 on Windows Server 2025 / Windows 11

Troubleshooting Guide: Error 9236 – “Database %.*ls is not a valid local database”

Why This Error Happens

This error occurs when SQL Server 2025 attempts to access a database file (typically an .mdf or .ldf file) that is either corrupted, mismatched with its associated log file, or was created by an incompatible version of SQL Server. It can also surface when a LocalDB instance’s metadata becomes desynchronized from the actual file structure on disk, often due to an improper shutdown or abrupt termination of the SQL Server process. Additionally, this issue is commonly triggered when a database file has been manually copied or moved without detaching it first, leaving the internal file header pointing to an invalid or non-existent local database reference.

Step-by-Step Resolution Guide

Step 1: Verify the LocalDB Instance Status

  • Open Command Prompt as Administrator on your Windows Server 2025 / Windows 11 machine.
  • Run sqllocaldb info to list all existing LocalDB instances.
  • Run sqllocaldb info MSSQLLocalDB (or your specific instance name) to check its current state (Running, Stopped, or Corrupted).
  • If the instance shows as corrupted or unresponsive, proceed to the next step.

Step 2: Stop and Delete the Corrupted LocalDB Instance

  • Stop the instance using: sqllocaldb stop MSSQLLocalDB -i
  • Delete the broken instance registration with: sqllocaldb delete MSSQLLocalDB
  • Navigate to C:\Users\<YourUsername>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\ and manually remove the leftover instance folder if it still exists.
  • Recreate a fresh instance using: sqllocaldb create MSSQLLocalDB

Step 3: Re-attach the Database Files Correctly

  • Open SQL Server Management Studio (SSMS) 2025 and connect to (localdb)\MSSQLLocalDB.
  • Use sp_detach_db on the source server (if accessible) before moving files in the future to avoid header corruption.
  • Attach the .mdf file manually via: CREATE DATABASE YourDBName ON (FILENAME = 'C:\Path\To\YourDB.mdf') FOR ATTACH;
  • If the .ldf log file is missing or mismatched, use FOR ATTACH_REBUILD_LOG instead to force SQL Server to regenerate a new log file.

Step 4: Check File Permissions and Integrity

  • Right-click the database folder (commonly located in C:\Users\<YourUsername>\Documents\ or your project’s App_Data folder) and go to Properties > Security.
  • Ensure the NT AUTHORITY\NETWORK SERVICE and your local Windows user account have Full Control permissions.
  • Run CHKDSK C: /F via an elevated Command Prompt to rule out underlying disk corruption affecting the .mdf/.ldf files.

Alternative or Verification Steps

  • To verify the fix, run SELECT name, state_desc FROM sys.databases; in SSMS and confirm the database state reads ONLINE rather than SUSPECT or RECOVERY_PENDING.
  • If the issue persists, restore the database from a recent .bak backup file using RESTORE DATABASE YourDBName FROM DISK = 'C:\Backups\YourDB.bak' WITH REPLACE; as a fallback to bypass the corrupted local file entirely.