Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GUID of 00000000-0000-0000-0000-000000000000 causing merge index violation

Our developer has a linq-2-sql project that talks to my database. The database is involved in merge replication. It has been in use for some time and was working fine. A recent table was added to the schema and now is causing problems when new records are added.

The user get's an error message stating that the index related to the guid that merge replication automatically creates is violating a unique constraint.

From what I can tell the table isn't any different than others that are involved. I have recreated the entire replication publication/subscription model from scratch and everything continues to work but that one table.

Anyone have any ideas? The guid being created appears as 00000000-0000-0000-0000-000000000000 which would explain why it's a duplicate. Why is a valid guid not being created by linq?

like image 792
RThomas Avatar asked Aug 09 '11 18:08

RThomas


3 Answers

Did you use "new Guid()" somewhere in your code base when what you meant was "Guid.NewGuid()"?

like image 188
MarkPflug Avatar answered Sep 30 '22 22:09

MarkPflug


I had faced the similar problem. As Mark has mentioned in the comment, the Guid() needs to be properly used.

Guid asm = new Guid(); // gives 00000000-0000-0000-0000-000000000000

Instead use

Guid asm = Guid.NewGuid();
like image 39
Vinay Avatar answered Sep 30 '22 22:09

Vinay


When using Linq-To-SQL, make sure the IsDbGenerated property is true and the Database actually is setup to create an ID (by using newid() as the default value).

Otherwise, make sure the .net code is actually generating IDs.

like image 32
Michael Stum Avatar answered Sep 30 '22 23:09

Michael Stum