Error while calling BuildFromDifferences (key not present)
JacobEwald
Posts: 4
I'm getting the following exception while calling BuildFromDifferences:
I'm using a snapshot created by the same version of the SDK to push the changes to 3 test databases. The problem only happens on 1 of the 3. The other weird thing is that I can use the exact same snapshot and push to the failing database using the SQL Compare UI and it works just fine. It seems to only be an issue with the SDK. I'm hoping someone can give me some direction on fixing this problem, thanks!
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at #8rg.#wvg..ctor(Permissions permissions, Permissions targetPermissions, Options options) at RedGate.SQLCompare.Engine.Permissions.#Ghh(SQLScriptBuilder #wUrc, Options #5OPb, Permissions #vUrc, Boolean #yUrc, Boolean #zUrc, String #xUrc, Boolean& #AUrc) at RedGate.SQLCompare.Engine.Work.#gQh(Options #5OPb, SQLScriptBuilder #wUrc, #yvg #mXrc, Boolean #yUrc) at RedGate.SQLCompare.Engine.Work.GenerateSql(Differences differences, Difference onlyDifferenceToInclude, Options options, Boolean runOnTwo) at RedGate.SQLCompare.Engine.Work.BuildFromDifferences(Differences differences, Difference onlyDifferenceToInclude, Options options, Boolean runOnTwo) at RedGate.SQLCompare.Engine.Work.BuildFromDifferences(Differences differences, Options options, Boolean runOnTwo)
I'm using a snapshot created by the same version of the SDK to push the changes to 3 test databases. The problem only happens on 1 of the 3. The other weird thing is that I can use the exact same snapshot and push to the failing database using the SQL Compare UI and it works just fine. It seems to only be an issue with the SDK. I'm hoping someone can give me some direction on fixing this problem, thanks!
Comments
Usually this sort of thing is caused by permissions. You may be using a different account when running the SDK app, so check the connection properties. If you set the ConnectionProperties to use SA and it works, that's definitely the problem.
If you need to narrow it down to a specific object, you can debug your app - when the exception breaks into the debugger, you can have a look at the locals and see if you can find the name of a SQL object (they almost always have brackets in the name).
Hope this helps.
When I debug the app and it throws the exception, I'm not sure exactly what I'm looking for in the locals. The Work object has an ExecutionBlock that looks correct, so it seems to have detected the changes without any problem, but the exception still throws.
It was one of 2 changes I made. There was a role that needed to own a schema, and a user needed to be added to that role. I did those two things manually though SQL Management Studio. The next time I ran the SDK app it succeeded without throwing that exception.
I would hope that this exception would be handled in a future version, but for now I'll know how to fix it if it comes up again.