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
- 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';
- 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''';
- 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.
- 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.
- 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.
- 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';
- 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
Source · learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors