SQLPackage error: An item with the same key has already been added
Asked Answered
C

3

6

I get this error from SQLPackage: "An item with the same key has already been added" What is the meaning? Google won't help me..

"c:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe" /Action:DeployReport /SourceFile:"XXX.dacpac" /Profile:"publish.xml" OutputPath:"Report.xml"

Generating report for database 'XXX' on server 'srv'.

* An item with the same key has already been added.

No output file is created.

Generate script from Visual Studio works (I get a script). I have tested with three projects in the same solution. Only one creates a DeploymentReport-file.

Publish works.

Cilla answered 21/3, 2014 at 13:21 Comment(2)
Do you have anything in your output report? Can you try generating a script to see what the script is trying to do? Does this happen before you run anything? What version of SSDT are you using? Does this happen if you run the Publish profile through the VS IDE?Desta
I did a quick Bing search on that message and one person seems to have had success by clearing out a cache. Can't say that will help you, but you might have some success there.Desta
R
10

I just ran into this issue. For anyone else who gets this, try the following.

  1. Delete the [project].dbmdl file in the root of the project folder.
  2. Close and re-open the project.
  3. Clean the solution/project.
  4. Build the DACPAC again.
  5. Publish/Script/Report the DACPAC.

I believe it is related to a cache of the dependancies becoming corrupt.

Richmal answered 16/2, 2016 at 16:35 Comment(0)
C
5

I was having the same issue. The weird thing was I could publish from Visual Studio without a problem, but as soon as I tried to publish from the command-line using SqlPackage I got this error.

For me it turned out that there were duplicate SqlCmdVariable's in my *.publish.xml file. I removed the duplicates and now publish without a problem from the command-line.

Coterminous answered 12/5, 2017 at 0:18 Comment(3)
In case in helps, the sqlcmd variable names are NOT case sensitive.Pyoid
I had duplicates due to different cases, so Eduardo's comment was spot on for meManning
I've checked for duplicate keys, in fact I just call sqlPackage with the target connection string and the dacpac, and I get the same error! This is true for the Azure deploy task too. It works in VS though. Can anyone give any pointers?Alimentation
G
1

I got the same error when deploying with SqlPackage.exe (with VS the deployment worked) but it wasn't an error in the publish file. My problem was, that I added the msdb two times with different versions. So please don't forget to check the Database-References for any duplicates.

Galibi answered 8/10, 2021 at 5:32 Comment(1)
This sounds highly plausible as I recently found SSDT makes a lot of problems when you try to remove and replace a database reference. Editing the actual project file is sometimes the only way to clean up the mess.Cerussite

© 2022 - 2024 — McMap. All rights reserved.