Error "Item has already been added. Key in dictionary:..."

RBohannonRBohannon Posts: 25
We are using SQL Data Compare 6.0 and the .NET 2.0 framework. I recently added code to our program to clean out the C:\WINDOWS\Temp\RedGate folder daily because the folder was getting unmanageably large on some workstations. Now we have one workstation (out of more than 20) that is throwing this error:

Item has already been added. Key in dictionary: 'C:\WINDOWS\TEMP\REDGAT~1\BEA4BE~1.LF' Key being added: 'C:\WINDOWS\TEMP\REDGAT~1\BEA4BE~1.LF'

The file name at the end varies with each program execution. Sometimes it's an LF file, sometimes a BF.

This error is getting thrown by mscorlib when one of these three Red Gate methods executes: ComparisonSession.TableDifferences, SqlProvider.GetMigrationSQL or ExecutionBlock.GetBatch. I haven't yet been able to determine which of these methods is throwing the error.

After researching this error, I found out that it means mscorlib attempted to insert a duplicate value into a hash table.

Any ideas what's going on?

Comments

  • Eddie DEddie D Posts: 1,802 Rose Gold 5
    Thank you for your post into the forum.

    Can you please confirm if you are using the SQL Data Compare API or using the SQL Data Compare GUI?

    If you are using the SQL Data Compare API, does your code include the following or similar statements?

    {
    session.Dispose();
    db1.Dispose();
    db2.Dispose();
    }

    Many Thanks
    Eddie
    Eddie Davis
    Senior Product Support Engineer
    Redgate Software Ltd
    Email: support@red-gate.com
  • API for SQL Data Compare 6.0.

    Yes on all three dispose statements. They execute at the end of the procedure in the Finally block.

    FYI, I'm comparing two SQL 2005 database backups.

    Also the problem is intermittent. It doesn't seem to be happening now but I didn't change anything. It happened several times in a row at one store location but the next day when the program ran it didn't happen. I just want to be able to prevent it from happening again.

    The machine reboots every night.
  • Eddie DEddie D Posts: 1,802 Rose Gold 5
    I have submitted a bug report to highlight this intermittent problem to the SQL Compare Development Team.

    By default SQL Data Compare creates the temp files in the Windows temp directory, however you can modify to use a different location by setting a new system variable called RGTEMP. If your workstation, laptop or server has multiple disk drives, you can configure to use a different drive letter.

    To set the new temp folder location, please follow steps below:

    1. Created a new folder on a different drive, for example D:\RGTemp.
    2. Right Click MyComputer and select properties.
    3. Select the Advanced Tab.
    4. Click on the Environment Variables button.
    5. In the System Variables section, click on the new button.
    6. The Variable name = RGTEMP and the Variable value = the path configured in step 1. In my example D:\RGTemp.
    7. Click the OK button on each dialog box to close.
    8. In some cases for the change to take effect, you may have to re-boot the machine.

    Once configured all Red gate application will create their temp files in the folder configured for the RGTEMP system variable.

    A new feature added to SQL Data Compare V.7 is the ability to compress the temp files created by the application. If you edit the project configuration ->Options Tab ->In the Comparison Behavior section there is an option, disabled by default, which you can enable to Compress the temp created by SQL Data Compare.

    If you have a valid Support & Upgrades Contract you can upgrade to Version 7 at zero cost.

    Many Thanks
    Eddie
    Eddie Davis
    Senior Product Support Engineer
    Redgate Software Ltd
    Email: support@red-gate.com
Sign In or Register to comment.