This sounds like you're trying to generate a surrogate key by your code. If that's the case, don't do it.
Instead use the database to create a unique value, for example
uniqueidentifier[
^].
Also if not already done so, you should define this column as the primary or secondary key.