// SQL Server error reference

SQL Server error 2812: Could not find stored procedure

The EXEC names a procedure that doesn't exist in the current database or schema, or a string was run as a procedure name by mistake.

Error number
2812
Severity
16
Category
Names and objects
Error message
Could not find stored procedure '%.*ls'.

What it means

EXEC name looks the procedure up in the current database, first in your default schema and then in dbo (and in master for system procedures whose names start with sp_). If no procedure has that name, you get 2812.

Common causes

  • The procedure is in another database or schema and the name isn't qualified.
  • A typo, or the procedure wasn't deployed to this environment.
  • Running a dynamic SQL string with EXEC @sql instead of EXEC (@sql): without parentheses SQL Server treats the whole string as a procedure name.

How to fix it

  1. Check that the procedure exists and where.

    SELECT SCHEMA_NAME(schema_id) AS schema_name, name
    FROM sys.procedures WHERE name LIKE N'%GetOrders%';
  2. Qualify the call with schema (and database if needed).

    EXEC SalesDb.Sales.GetOrders @CustomerId = 42;
  3. Run dynamic SQL with parentheses, or better with sp_executesql.

    DECLARE @sql nvarchar(max) = N'SELECT TOP (5) name FROM sys.objects';
    EXEC (@sql);
    EXEC sys.sp_executesql @sql;

Reproduce it safely

DECLARE @sql nvarchar(100) = N'SELECT 1';
EXEC @sql;  -- Msg 2812: Could not find stored procedure 'SELECT 1'.

Related errors

More names and objects errors

The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.

// fewer errors, faster fixes

Work on SQL Server in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.