>Can anyone tell me why code sometimes only runs correctly when in debug mode. In this particular instance I am using a method to scan through a table and add new records on the basis of certain criteria in the existing records. The primary key field is set to be automatically generated by newid(). If I run the code in debug the field is generated successfully, if I run the application normally I get the error "Uniqueness of index is violated" because the primary key is not being generated.
>
>Any help would be greatly appreciated.
>
>J.Thomason
John,
Are you using SYS(3) or SYS(2015) for the unique ID? If you are you have a time dependent problem. SYS(3) and SYS(2015) can both return same values on very fast computers. The reason it works with debug on is that debug slows the code down. Both sys(3) and sys(2015) base their values on the system clock and the clock only ticks every 1/18th of a second. So if you hit your NewId function within 1/18th of a secodn from the last hit, you will get the same ID.