SQL Server error 2812 ("Could not find stored procedure") stops queries dead in their tracks, blocking critical workflows. This error typically means the system can’t locate a procedure defined in your database—often due to case-sensitivity mismatches, schema changes, or missing dependencies. Here’s how to diagnose and resolve it quickly.

What You'll Need

  • A SQL Server client tool (SSMS, SQL Server Management Studio) or command-line client (SQLCMD, PowerShell)
  • Access to the database server (manageable permissions to check procedures)
  • Optional: Full backup of the database during troubleshooting

Step-by-Step

  1. Confirm the exact procedure name and case sensitivity
    1. Run a query to verify the procedure’s existence: EXEC sp_help_procedure 'YourDatabaseSchema.YourProcedureName' (replace placeholders with actual names).
    2. If the procedure returns null, check the stored procedure name in your source code or deployment script—case sensitivity matters in SQL Server.
    3. Compare the case of the procedure name between:
      • The stored procedure definition (output of sp_help)
      • The query calling it
  2. Verify the procedure exists in the correct schema
    1. Run: SELECT OBJECT_NAME(DEFINE_OWNER_SCHEMA_ID(object_id)) FROM sys.sql_modules WHERE definition LIKE '%YourProcedureName%' (replace with your procedure name).
    2. If OBJECT_NAME doesn’t return your schema, the procedure may be in a different schema than expected. Use: SELECT SCHEMA_NAME(schema_id) FROM sys.schemas WHERE schema_id IN ( SELECT schema_id FROM sys.sql_modules WHERE definition LIKE '%YourProcedureName%' )
    3. If needed, alter the procedure to match the expected schema: EXEC sp_rename 'YourSchema.YourProcedureName', 'NewSchema.YourProcedureName'
  3. Check for dependencies that may break the procedure
    1. Run this query to see if the procedure depends on other objects: SELECT NAME, TYPE_NAME, DEFINITION FROM sys.sql_expression_dependencies WHERE parent_id = OBJECT_ID('YourDatabaseSchema.YourProcedureName')
    2. If dependencies reference objects that don’t exist (or have been dropped), the procedure can’t load. For example:
      • Table views may have become invalid
      • Other procedures might have been altered
    3. Fix by:
      1. Recreating the procedure
      2. Altering dependent objects
  4. Recreate the procedure if corrupted
    1. Use a backup or source control to restore the procedure definition.
    2. For stored procedures created via scripts, run the script again: EXEC sp_verifyproc 'YourProcedureName' to validate syntax.
    3. If the procedure was created via ALTER, check for:
      • Unterminated statements
      • Syntax errors in the procedure body
  5. Check for permissions that block access
    1. Run: SELECT * FROM sys.database_principals WHERE name IN ( SELECT principal_id FROM sys.database_permissions WHERE grantee_principal_id IN ( SELECT object_id FROM sys.sql_modules WHERE definition LIKE '%YourProcedureName%' ) )
    2. If the user lacks permissions, grant them: ALTER PROCEDURE on object::YourDatabaseSchema.YourProcedureName to your_principal_name
  6. Verify the database is online and the procedure isn’t marked as dropped
    1. Run: SELECT name, is_dropped FROM sys.procedures WHERE name = 'YourProcedureName'
    2. If is_dropped returns true, drop and recreate the procedure.
    3. Check for database connectivity issues if queries report "unable to start TDS" errors.

Common Mistakes

  • Assuming case-insensitive behavior: SQL Server is case-sensitive for identifiers (procedure names, schemas). Always validate exact case matches.
  • Ignoring dependencies: A procedure often depends on tables, views, or other procedures. Dropping one without fixing dependencies can break another.
  • Using incorrect syntax in deployment scripts: Procedures defined via scripts must match the exact syntax of the stored procedure in the database.
  • Overlooking schema mismatches: The procedure might exist but be in the wrong schema in your application code.

Tips

  • Use sp_helprouter to list all available stored procedures in a database and compare them with your application’s expected list.
  • For large databases, export procedure definitions to text files using sp_helptext and compare versions.
  • Set up a script to check for missing procedures regularly by querying sys.procedures and comparing with your application’s expected procedures.
  • Enable SQL Server trace flags (65300) for detailed error information if the error persists, though this may impact performance.
  • Check for dual-use identifiers: A procedure might be named the same as a table or function in the same database.

Troubleshooting

  1. If basic checks fail: Restart the SQL Server service (sqlservr.exe on Windows) or restart the database in single-user mode:
    1. Take a backup
    2. Run ALTER DATABASE YourDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    3. Recreate the procedure
    4. Return to multi-user mode
    5. ALTER DATABASE YourDatabaseName SET MULTI_USER
  2. If permissions are the culprit: Add the user to the db_owner fixed role via: ALTER ROLE db_owner ADD MEMBER 'YourUser' (requires DBA privileges)
  3. If the database is corrupted: Restore from a recent backup, then validate:
    1. Check sys.dm_db_index_usage_stats for missing indexes
    2. Verify object dependencies
  4. For production systems: Test the procedure in a non-production environment first to isolate the issue.

Frequently Asked Questions

Why does SQL Server error 2812 keep happening after I've recreated the procedure?

The error persists if there’s a mismatch between the procedure definition and how it’s referenced. Check for:

  • Case sensitivity in the procedure call
  • Schema mismatches between the definition and usage
  • Permissions on the procedure or referenced objects
  • Dual-use identifiers (same name as a table or function)

How do I check all procedures in my database for missing dependencies?

Run this script: SELECT p.name AS ProcedureName, t.name AS TableName, f.name AS FunctionName, u.name AS UserTableName FROM sys.procedures p JOIN sys.sql_expression_dependencies deps ON p.object_id = deps.parent_id LEFT JOIN sys.tables t ON deps.referenced_id = t.object_id AND deps.referenced_class = 7 LEFT JOIN sys.functions f ON deps.referenced_id = f.object_id AND deps.referenced_class = 0 LEFT JOIN sys.all_objects u ON deps.referenced_id = u.object_id AND deps.referenced_class = 11 WHERE deps.referenced_class IN (7, 0, 11) AND deps.referenced_id IS NULL

Can SQL Server error 2812 occur if the procedure was created via ALTER?

Yes, errors in the procedure body (unterminated statements, syntax errors) will prevent it from loading. Always validate:

  • The procedure returns a valid result set
  • There are no syntax errors using sp_verifyproc
  • The ALTER statement was executed correctly (check execution plan)

What should I do if I can't find the procedure definition anywhere?

Check these sources:

  • Your version control system (if the procedure was defined in a script)
  • Deployment pipelines or configuration management tools
  • Previous database backups
  • Development environment where the procedure was originally created

How do I fix a procedure that was moved to a different schema?

Use sp_rename to move the procedure: EXEC sp_rename 'OldSchema.ProcedureName', 'NewSchema.ProcedureName', 'PROCEDURE' Then update all references in your application code to use the new schema.

Why does error 2812 show up in production but not in development?

Possible causes include:

  • Schema differences between environments
  • Case sensitivity differences in procedure names
  • Missing dependencies in production (e.g., views were dropped)
  • Permissions were granted only in development
  • The procedure was defined with different syntax (e.g., SQL Server version differences)