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

Troubleshooting Guide: SQL Server Error 2520 — “Could not find database”

Why This Error Happens

This error typically occurs when a database reference in a query, connection string, or application points to a database name that either no longer exists, was renamed, or was never fully attached/restored on the target SQL Server 2025 instance. It can also happen when the database exists in sys.databases but is in an inaccessible state (such as SUSPECT, OFFLINE, or still in RECOVERY_PENDING), causing the engine to treat it as unavailable. Additionally, case-sensitivity mismatches in the database name or a user connecting to the wrong instance (especially with named instances or multiple SQL Server 2025 installations on the same Windows Server 2025 host) can trigger this behavior.

Step-by-Step Resolution Guide

Step 1: Verify the Database Actually Exists on the Instance

  • Open SQL Server Management Studio (SSMS) or Azure Data Studio and connect to the exact instance referenced in your connection string (e.g., SERVERNAME\INSTANCENAME).
  • Run the following query to list all databases currently visible to the engine:
  SELECT name, state_desc FROM sys.databases;
  • Confirm the database name matches exactly (including spelling and case) with what your application or script is requesting.

Step 2: Check Database State and File Locations

  • If the database is listed but shows a state other than ONLINE (e.g., RECOVERY_PENDING, SUSPECT, OFFLINE), this is likely the true root cause rather than a missing database.
  • Check the default data and log file paths, typically located at:
  C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\
  • If the .mdf/.ldf files were moved or deleted, reattach the database manually:
  CREATE DATABASE YourDBName 
  ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\YourDBName.mdf')
  FOR ATTACH;

Step 3: Confirm You Are Connecting to the Correct Instance

  • On systems with multiple SQL Server 2025 instances, verify the correct instance name using SQL Server Configuration Manager under SQL Server Services.
  • Cross-check the connection string / application appsettings.json or web.config file to ensure the Server= or Data Source= value matches the instance hosting the target database.
  • If using a container or Windows failover cluster, ensure the database wasn’t left behind on a different node after failover.

Step 4: Restore or Recreate the Database if Missing

  • If the database genuinely does not exist, restore from the latest .bak file:
  RESTORE DATABASE YourDBName 
  FROM DISK = 'C:\Backups\YourDBName.bak' 
  WITH RECOVERY;
  • If no backup exists, recreate the schema and reimport data from your source control or ETL pipeline.

Alternative or Verification Steps

  • After applying fixes, run SELECT DB_ID('YourDBName'); — a non-NULL result confirms the database is now recognized by the instance.
  • If the error persists, check the SQL Server error log (ERRORLOG file in the MSSQL\Log folder) for underlying I/O or permission errors that may be preventing the database from coming online.