MetricSign
Start free
Medium severityschema

SQL Server Error:
2812

What does this error mean?

SQL Server raises error 2812 when an EXEC or sp_executesql call references a stored procedure name that does not exist in the current database context. In data-pipeline scenarios this typically surfaces during an Azure Data Factory Stored Procedure activity, a Synapse notebook, or a Power BI dataset refresh that calls a proc as its source query. The engine resolves the procedure name at execution time — not at deployment or validation — so the pipeline may pass validation in ADF Studio but fail at runtime. The symptom is an immediate failure with no partial execution: the batch is aborted, the ADF activity status flips to Failed, and downstream activities in the same pipeline are skipped unless you configured explicit failure paths.

Common causes

  • 1The stored procedure was not deployed to the target environment. Common when CI/CD deploys the ADF ARM template but the dacpac or migration script for the database was skipped or failed silently.
  • 2Schema mismatch: the ADF activity references dbo.usp_Load but the procedure was created under a different schema like etl.usp_Load. SQL Server treats schema as part of the object identity.
  • 3The procedure was renamed or dropped after the pipeline was last configured. A refactor in the database project removes the old name but nobody updates the ADF JSON.
  • 4Database context is wrong: the linked service or connection string points to master, tempdb, or a different user database than the one containing the procedure.
  • 5Dynamic SQL constructs the procedure name at runtime (e.g. EXEC(@procName)) and the variable contains a typo, an extra space, or a NULL value that resolves to a non-existent name.
  • 6Permissions masking existence: the executing service principal has no EXECUTE permission on the proc's schema. SQL Server returns 2812 rather than a permissions error when the caller also lacks VIEW DEFINITION on the object.

How to fix it

  1. 1Step 1: Confirm the procedure exists in the correct database. Connect with SSMS or Azure Data Studio and run: SELECT SCHEMA_NAME(schema_id) AS schema_name, name, create_date, modify_date FROM sys.procedures WHERE name = 'usp_YourProcName';
  2. 2Step 2: If the query returns no rows, check all databases on the server: EXEC sp_MSforeachdb 'USE [?]; SELECT DB_NAME() AS db, SCHEMA_NAME(schema_id) AS schema_name, name FROM sys.procedures WHERE name = ''usp_YourProcName''';
  3. 3Step 3: Verify the linked service database context in ADF. Open the linked service → Connection properties → check the 'Database name' field. If it says master or a different DB, update it.
  4. 4Step 4: Use the fully schema-qualified name in the ADF Stored Procedure activity. In the activity settings, set Stored procedure name to [etl].[usp_YourProcName] rather than just usp_YourProcName.
  5. 5Step 5: If the proc was dropped, redeploy it. From your database project: sqlpackage /Action:Publish /SourceFile:YourDb.dacpac /TargetConnectionString:"Server=...;Database=...;" — or run the CREATE PROCEDURE script manually.
  6. 6Step 6: Verify the executing identity has EXECUTE permission: SELECT dp.name, dp.type_desc, perm.permission_name, perm.state_desc, OBJECT_NAME(perm.major_id) AS object_name FROM sys.database_permissions perm JOIN sys.database_principals dp ON perm.grantee_principal_id = dp.principal_id WHERE OBJECT_NAME(perm.major_id) = 'usp_YourProcName';
  7. 7Step 7: Test the fix by triggering a debug run of the pipeline in ADF Studio. Monitor the output pane for the activity to confirm it completes without 2812.

Example log output

Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'etl.usp_LoadFactSales'.
Failure happened in Activity 'Stored Procedure1' of pipeline 'PL_Load_FactSales'. Error code: 2812.

Frequently asked questions

How do I list all stored procedures in a SQL Server database?

Run: SELECT SCHEMA_NAME(schema_id) AS schema_name, name, create_date, modify_date FROM sys.procedures ORDER BY schema_name, name; — This returns every proc with its schema, which helps you spot naming or schema mismatches causing 2812.

Can error 2812 appear in Power BI?

Yes. If a Power BI dataset uses a stored procedure as its source query (via EXEC) and the procedure is dropped, renamed, or lives in a different schema, the scheduled refresh fails with 2812. Check the refresh history in Power BI Service → Settings → Datasets for the exact error message.

Does SQL Server retry error 2812 automatically?

No. Error 2812 is a compile-time error — the batch is aborted before execution starts. There is no built-in retry. In ADF you can configure a retry policy on the activity (e.g. retry 2, interval 30s), but retries will keep failing until the procedure actually exists. Retrying a missing object wastes activity run quota.

Why do I get 2812 even though the stored procedure exists?

Three common reasons: (1) the connection string or linked service points to a different database than you think — check SELECT DB_NAME(); (2) the proc is under a non-default schema and you are calling it without the schema prefix; (3) the executing service principal lacks VIEW DEFINITION and EXECUTE permissions on the schema, which causes SQL Server to report the object as not found rather than returning a permission denied error.

Source · learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors

Other schema errors