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.

SAS
  • 3,943
  • 2
  • 27
  • 48
  • 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? – Peter Schott Mar 21 '14 at 14:43
  • 1
    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. – Peter Schott Mar 21 '14 at 18:55

3 Answers3

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.

sean
  • 1,187
  • 17
  • 25
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.

KiwiPiet
  • 1,304
  • 14
  • 21
  • 3
    In case in helps, the sqlcmd variable names are NOT case sensitive. – Eduardo Hernández Aug 09 '18 at 08:09
  • 1
    I had duplicates due to different cases, so Eduardo's comment was spot on for me – user2197446 Jan 24 '19 at 16:28
  • 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? – Hoecuspocus Oct 04 '19 at 15:01
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.

  • 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. – Phil Morris May 19 '22 at 09:31