Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 514
SAS Avatar asked Mar 21 '14 13:03

SAS


People also ask

What does an item with the same key has already been added mean?

Your item with the same key has already been added is also an utra general error, but typically it can be trying to set the same key in a database (or forgetting to set a key with no default value, hence for instance if an int, then all rows would be 0, de default) or a dictionary.

What is SqlPackage?

SqlPackage.exe is a command-line utility that automates the following database development tasks by exposing some of the public Data-Tier Application Framework (DacFx) APIs: Version: Returns the build number of the SqlPackage application.


2 Answers

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.

like image 85
sean Avatar answered Sep 28 '22 16:09

sean


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.

like image 45
KiwiPiet Avatar answered Sep 28 '22 17:09

KiwiPiet