An item with the same key has already been added.

A SQL Server Management Studio add-in to source control your database in Subversion or Team Foundation Server.

An item with the same key has already been added.

Postby sidharthnayyar » Wed Apr 04, 2012 2:11 pm

Dear All,

I've got SQL Source Control 3.0.6.25 but only today I've started getting a strange error on one of my version controlled databases (SVN btw).

Any ideas how I can fix this?

Kind regards
Sidharth
RedGate.SQLSourceControl.Engine.SqlCompareException: An item with the same key has already been added. ---> System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at RedGate.SQLCompare.Engine.KeyedCollection`1.Add(T value)
at RedGate.SQLCompare.Engine.ReadFromFolder.ReadScriptAnalysis.#5Ih(Constraint #ZKPb, Table #fvPb, Boolean #W1rc, AlterTable #X1rc)
at RedGate.SQLCompare.Engine.ReadFromFolder.ReadScriptAnalysis.#4Ih(Element #wpUb)
at RedGate.SQLCompare.Engine.ReadFromFolder.ReadScriptAnalysis.#SHh(AST #iAPb)
at RedGate.SQLCompare.Engine.ReadFromFolder.ReadScriptAnalysis.#SHh(AST #iAPb)
at RedGate.SQLCompare.Engine.ReadFromFolder.ReadScriptAnalysis.VisitNode(Element node, AnalysisProvider`1 provider)
at RedGate.SQLCompare.Rewriter.Analysis.Analyser`1.#hbh(Element #fpl)
at RedGate.SQLCompare.Rewriter.Analysis.Analyser`1.Analyse(IEnumerable`1 elements)
at #Eyg.#Gyg.#CGh(FileInfo #mDk)
at #Eyg.#Gyg.#vl(IEnumerable`1 #rXrc)
at RedGate.SQLCompare.Engine.Database.Register(String path, ScriptDatabaseInformation dbinfo, Options options, IEnumerable`1 filesToUse, IReadFromFolderCache cache)
at RedGate.SQLCompare.Engine.Database.Register(String path, ScriptDatabaseInformation dbinfo, Options options, IEnumerable`1 filesToUse)
at RedGate.SQLCompare.Engine.Database.Register(String path, ScriptDatabaseInformation dbinfo, Options options)
at #qlhb.#L3c.#y25.#nKcb()
at #GWeb.#7Jf.#gKf(Action )
--- End of inner exception stack trace ---

Server stack trace:
at #GWeb.#7Jf.#gKf(Action )
at #GWeb.#7Jf.#z21.#rkW()
at RedGate.SQLSourceControl.Engine.SharedUtilsUtils.DoActionWithCancel(ICancellableOperationStatus status, ICancellable cancellable, Action action)
at #GWeb.#7Jf.#jKf(ICancellableOperationStatus , ICancellable , Action )
at #qlhb.#L3c.#l36(String , #x36 , ICancellableOperationStatus )
at #qlhb.#K3c.#83c(String , #O9U , ICancellableOperationStatus , IReadOnlySourceControlServerCallBacks )
at #qlhb.#L3c.#f6c(String , ScriptDatabaseInformation , Options , ICancellableOperationStatus , IReadOnlySourceControlServerCallBacks )
at #GWeb.#WXM.#f6c(String )
at #GWeb.#XXM.#Qy2b()
at #GWeb.#Wheb.#tieb(Func`1 )
at #GWeb.#XXM.#Py2b()
at RedGate.SQLSourceControl.Engine.Cancellables.CancellableUtils.#y21.#RKc()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
at System.Action.EndInvoke(IAsyncResult result)
at RedGate.SQLSourceControl.Engine.Cancellables.CancellableUtils.DoInParallel(ICancellableOperationStatus status, Pair`2[] labelledActions)
at #GWeb.#WXM.#rYM()
at #GWeb.#WXM.#qYM()
at #GWeb.#XXM.#iS()
at #qlhb.#0heb.#l36(String , #1heb , ICancellableOperationStatus )
at #qlhb.#K3c.#83c(String , #O9U , ICancellableOperationStatus , IReadOnlySourceControlServerCallBacks )
at #qlhb.#0heb.#wieb(#L3c , #ZZ7 , #A57 , #tEc , IObjectExplorerStateService , #xHR , #9ynb , #4Ec , #j3l , Options , #quBb , ICancellableOperationStatus , IReadOnlySourceControlServerCallBacks )
at #GWeb.#VXM.#mYM[#NrPb](Func`2 , ICancellableOperationStatus , IReadOnlySourceControlServerCallBacks , IDifferenceSelector )
at #GWeb.#VXM.#jYM(ICancellableOperationStatus , IReadOnlySourceControlServerCallBacks , IDifferenceSelector )
at #GWeb.#4Ec.#7Jc(ICancellableOperationStatus , IReadOnlySourceControlServerCallBacks , IDifferenceSelector )
at #GWeb.#4Ec.#y26.#QB7b(ICancellableOperationStatus )
at RedGate.SQLSourceControl.Engine.Cancellables.MutexedCancellableOperation`1.#u36.#k5f()
at RedGate.SQLSourceControl.Engine.Cancellables.CancellableOperationBase.InvokeWithTracker(String featureUsageKey, Action action)
at RedGate.SQLSourceControl.Engine.Cancellables.MutexedCancellableOperation`1.Invoke()
at #eEc.#Qlg.Invoke()
at #JLc.#PLc.#Jfb.#EJf()
at RedGate.SQLSourceControl.Engine.SmartAssembly.ExceptionReporting.ErrorReporterBase.Do(Action , Predicate`1 , Boolean )
at RedGate.SQLSourceControl.Engine.SmartAssembly.ExceptionReporting.ErrorReporterBase.DoWithObviousExceptionsRethrowAll(Action action)
at RedGate.SQLSourceControl.CommonUI.Forms.ErrorDialog.DoWithObviousExceptionsRethrowAll(Action action)
at #JLc.#PLc.#CTc(ICancellableOperation`1 , Object )
sidharthnayyar
 
Posts: 6
Joined: Wed Apr 04, 2012 2:03 pm

Postby james.billings » Fri Apr 06, 2012 4:24 pm

Hi,
There's a few things that can cause this. Usually though, it's because you have duplicate definitions somewhere for one or more objects. This can happen if you have maybe made a backup copy of one of the files in SVN? If you click the "Send error report" option and enter your email address I can see if it contains further information.

The other possibility is when you have objects that differ in name only in whitespace. I think we changed the default to not be a problem any more, but you can double check by running this query:

Code: Select all
SELECT
*
FROM
sys.sysobjects a
INNER JOIN sys.sysobjects b ON REPLACE(RTRIM(LTRIM(a.name)),' ','') = REPLACE(RTRIM(LTRIM(b.name)), ' ','') AND a.id <> b.id


Any results from that can potentially cause the error as well.
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

Postby sidharthnayyar » Fri Apr 06, 2012 4:35 pm

Hi James,

I've sent the error report to you.

That SQL did return some results but it makes no sense to me!

Code: Select all
fn_cdc_get_all_changes_ ...    606065345
fn_cdc_get_all_changes_...   574065231
fn_cdc_get_net_changes_ ...    622065402
fn_cdc_get_net_changes_...   590065288


That's name and id from the result

Thanks
Kind regards
Sidharth
sidharthnayyar
 
Posts: 6
Joined: Wed Apr 04, 2012 2:03 pm

Postby james.billings » Fri Apr 06, 2012 4:39 pm

They may cause the problem. Basically, those will be four functions. You'll see that for each pair, they are named the same asides from a space between the _ and the ...

The default behaviour of SQL Source Control used to be (and may still be) that it ignores whitespace, so essentially you end up with two functions being seen as the same thing. That leads to the error.

Do you know if you definitely need all four of those functions? It looks more like one of each is either a typo or created in error... if you can remove the files for the problematic ones from SVN then re-link your database the problem may well go away. I'll keep an eye open for the error report if that refers to different objects though.
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

Postby sidharthnayyar » Fri Apr 06, 2012 5:06 pm

Hi James,

Thanks for the reply. I've not created those functions! That's very strange. I'll see if deleting it from SVN fixes that problem - I have to leave just now though so it'll next week when I check this.

Thanks and kind regards
Sidharth
sidharthnayyar
 
Posts: 6
Joined: Wed Apr 04, 2012 2:03 pm

Postby james.billings » Fri Apr 06, 2012 5:07 pm

No worries - let us know how you get on
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

Postby sidharthnayyar » Mon Apr 09, 2012 10:07 am

Hi James,

I think I've found the problem. I had enabled Change Data Capture and DB Auditing for the database and that must've caused SQL Source Control to stop working. I've removed all objects from SVN, relinked and it's worked. And I've also disabled and removed all CDC objects. Hopefully that should work now.

However, I may need to enable CDC in the future - can you confirm Source Control works with CDC enabled?

Kind regards
Sidharth
sidharthnayyar
 
Posts: 6
Joined: Wed Apr 04, 2012 2:03 pm

Postby james.billings » Tue Apr 10, 2012 12:28 pm

Interesting - I'm not aware of any issues with CDC, and I've managed to enable it on a database myself without any issue.
More likely is that by clearing up your SVN contents, you've removed whatever rogue file had a duplicate object definition in it.
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

Postby sidharthnayyar » Tue Apr 10, 2012 5:15 pm

Hi James,

Okay, that's good to know. Thanks for all your help.

Kind regards
Sidharth
sidharthnayyar
 
Posts: 6
Joined: Wed Apr 04, 2012 2:03 pm

Same Error. How do I fix it?

Postby pmcdermott » Mon Apr 16, 2012 9:04 pm

I have the same error, though sometimes it alternates to this one: "A duplicate definition was found for the table [dbo].[#tmpErrors]". I am using the same version but with TFS. When I ran the query you mentioned above, I had 94 rows. I haven't had this problem before though. I tried unlinking and re-linking the database from TFS, but that didn't fix it. How do I resolve the problem?
Thanks!
pmcdermott
 
Posts: 3
Joined: Tue Nov 04, 2008 6:49 pm

Postby james.billings » Tue Apr 17, 2012 11:51 am

The query will return items that differ only in whitespace and are probably being treated as identical (what version are you on?)

It's unusual to get this message for something like temporary tablenames like that though; unless those definitions are in their own file or something?
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.


Return to SQL Source Control 3

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest