Troubleshooting Guide: SQL Server Error 2310 – “The attribute ‘%ls’ is declared more than once”
Why This Error Happens
This error occurs when SQL Server 2025 parses an XML Schema Collection, XML document, or SSIS/DACPAC metadata file (such as a .dacpac, .bacpac, or XSD-based schema) that contains a duplicate attribute definition within the same element or complex type. This is typically caused by a corrupted or manually edited XML/schema file, a flawed schema merge during an upgrade from a previous SQL Server version, or a third-party tool generating malformed XML with redundant attribute declarations. Because the XML parser enforces strict uniqueness constraints on attribute names within a given scope, it rejects the entire schema or document load, halting the associated operation (e.g., CREATE XML SCHEMA COLLECTION, SSDT deployment, or Service Broker message validation).
Step-by-Step Resolution Guide
Step 1: Identify the Offending XML Source
- Check the SQL Server Error Log at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGfor the full error context, including the schema collection name or file path. - If triggered by a deployment, inspect the
.dacpac/.bacpacfile by renaming it to.zipand extracting it to reviewmodel.xmlfor duplicate attributes (e.g., search for repeatedName=entries within the same<Element>tag). - Run the following to identify the schema collection in question:
SELECT name, xml_schema_namespace FROM sys.xml_schema_collections;
Step 2: Correct the Duplicate Attribute in the Source File
- Open the identified XML/XSD file in a validating editor (Visual Studio 2025 or VS Code with the XML extension installed).
- Locate the element flagged in the error message and remove or rename the duplicate attribute so each attribute name appears only once per element scope.
- Save the file with UTF-8 encoding to avoid introducing hidden byte-order-mark (BOM) corruption that can also trigger parser errors.
Step 3: Re-register or Re-import the Corrected Schema
- If the error originates from a schema collection, drop and recreate it:
DROP XML SCHEMA COLLECTION dbo.MySchemaCollection;
GO
CREATE XML SCHEMA COLLECTION dbo.MySchemaCollection AS N'<corrected XML content>';
GO
- For DACPAC/BACPAC deployments, re-zip the corrected
model.xmlback into the package and redeploy usingSqlPackage.exefrom an elevated PowerShell prompt on Windows Server 2025. - Clear any cached deployment artifacts in
%TEMP%\SqlPackageTempbefore retrying.
Step 4: Validate Upstream Tooling
- If the file was auto-generated (e.g., via SSDT, SSIS, or a CI/CD pipeline), update the generating tool to the latest version, as older versions are known to emit duplicate attribute nodes during schema merges.
- Re-run the generation process and re-diff the output XML against the previous corrupted version.
Alternative or Verification Steps
- Validate the fix by re-running the original failing command (schema creation, deployment, or Service Broker message send) and confirming Error 2310 no longer appears in the Error Log or SSMS output pane.
- As an alternative, use an XSD validation tool (e.g.,
xmllint --noout --schemaor Visual Studio’s “Validate XML” feature) against the corrected file before reloading it into SQL Server to catch any remaining structural issues proactively.