Troubleshooting Guide: SQL Server Error 12835
Why This Error Happens
This informational message is raised automatically when SQL Server alters the containment option of a database (switching it to PARTIAL or NONE). The engine must refresh the definitions of objects—such as views, stored procedures, or functions—that depend on a builtin function, because contained databases resolve collations and metadata differently than non-contained ones. This typically occurs during a containment state transition and is often benign, but it can surface unexpectedly if automated deployment scripts or migration tools change containment settings without accounting for dependent object recompilation.
Step-by-Step Resolution Guide
Step 1: Confirm the Context of the Message
- Check whether Error 12835 appeared during a deliberate
ALTER DATABASE ... SET CONTAINMENToperation. - Run the following to check current containment status:
SELECT name, containment, containment_desc FROM sys.databases WHERE name = 'YourDatabaseName';
- If this message appeared unexpectedly (not tied to a containment change), investigate the SQL Server Error Log at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGfor the triggering statement.
Step 2: Validate Dependent Object Definitions
- Identify objects referencing builtin functions that may have been refreshed:
SELECT referencing_schema_name, referencing_entity_name, referenced_entity_name
FROM sys.dm_sql_referenced_entities('dbo.YourObjectName', 'OBJECT');
- Script out and compare the object definitions before and after containment change using SSMS “Generate Scripts” to ensure no unintended logic changes occurred.
- Pay special attention to objects using functions like
SUSER_SNAME(),USER_NAME(), or collation-sensitive string functions, as these are most affected by containment changes.
Step 3: Re-run the Containment Change in a Controlled Window
- Schedule the containment change during a maintenance window:
ALTER DATABASE YourDatabaseName SET CONTAINMENT = PARTIAL;
- Immediately after, recompile affected objects explicitly to force metadata validation:
EXEC sp_recompile 'dbo.YourObjectName';
- Review the SQL Server Error Log again to confirm Error 12835 entries correspond only to expected objects.
Step 4: Update Deployment and Migration Scripts
- If using DACPAC/BACPAC deployment or Azure Data Studio migration tools on Windows Server 2025, add a post-deployment step to validate object recompilation.
- Avoid toggling containment settings repeatedly in automated CI/CD pipelines without a verification gate.
Alternative or Verification Steps
- Query
sys.messagesfor message ID 12835 to confirm it is a Level 10 informational message (not a failure), ensuring no rollback or application impact occurred. - If object behavior seems incorrect post-refresh, drop and recreate the specific dependent object manually, then re-apply the containment change to force a clean metadata refresh.