Troubleshooting Guide: SQL Server Error 2218 — “There is no attribute named ‘@%ls'”
Why This Error Happens
Error 2218 occurs when SQL Server’s XML parser processes an XML-formatted configuration file, SSIS package, or XML schema collection and encounters an attribute reference that doesn’t exist in the current node context. This is typically caused by a corrupted or manually-edited XML file (such as a Policy-Based Management policy, Maintenance Plan, or SSIS .dtsx package) where an attribute was renamed, removed, or mistyped during an incomplete version upgrade or migration. It can also surface when a third-party tool or extension generates malformed XML that references deprecated attributes no longer supported in SQL Server 2025’s updated XML schema definitions.
Step-by-Step Resolution Guide
Step 1: Identify the Source XML File or Object
- Check the SQL Server error log at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGfor the full stack trace surrounding Error 2218. - Note the specific attribute name (
@%lsis a placeholder populated at runtime) and the object type (SSIS package, Policy, Extended Event session, etc.). - If triggered by an SSIS job, open SQL Server Agent job history under
Object Explorer > SQL Server Agent > Jobsto pinpoint the exact step and package path.
Step 2: Validate the XML Against Its Schema
- Open the suspect
.dtsx,.xml, or.policyfile in a text editor (Notepad++ or VS Code) and locate the attribute referenced in the error. - Run
Invoke-XmlValidationin PowerShell (or usexmllint --noout --schema schema.xsd file.xmlif the Linux tools are installed) to confirm the file conforms to its expected XSD. - Compare the file against a known-good backup copy stored in version control or a prior deployment package.
Step 3: Repair or Regenerate the Corrupted Object
- If it’s an SSIS package, reopen the project in SQL Server Data Tools (SSDT) 2025, rebuild the package, and redeploy it via
dtutilor the Integration Services Catalog. - If it’s a Policy-Based Management policy, drop and reimport the policy using
Import-SqlPolicyor re-export a clean copy from a healthy instance. - For Extended Events sessions, run
DROP EVENT SESSION [SessionName] ON SERVER;followed by a freshCREATE EVENT SESSIONscript generated from the current catalog views.
Step 4: Clear Cached Metadata and Restart Services
- Stop the SQL Server service via
Stop-Service -Name 'MSSQLSERVER'in an elevated PowerShell session. - Clear any cached plan or policy cache using
DBCC FREESYSTEMCACHE('ALL')before shutdown if the instance is still responsive. - Restart the service with
Start-Service -Name 'MSSQLSERVER'and monitor the ERRORLOG for recurrence.
Alternative or Verification Steps
- Re-run the operation that originally triggered Error 2218 (job execution, policy evaluation, or package deployment) and confirm the ERRORLOG shows no further XML parsing errors.
- If the error persists, use
sp_helptextorOBJECT_DEFINITION()to extract any embedded XML from system objects and manually diff it against Microsoft’s documented schema for SQL Server 2025 to isolate the invalid attribute.