question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deleted row (Primary key) on the server causes conflict when client adds new record

See original GitHub issue

Hi - Iam using dotmim to sync a sqlite client with a sql server database. When I delete a row in management studio. A cannot add any records from the client in the same table (upload 1, conflict 1). I am guessing there is a primary key conflict, as the primary key that the client is trying to use is not acceptable to sql server. Is there a simple fix? Can I set sql server to reseed? or are UniqueIdentifiers/Guids the way forward? Thanks in advance - Pete ` var serverProvider = new SqlSyncChangeTrackingProvider(@“connectionstring;”);

    var clientProvider = new SqliteSyncProvider("Record.db3");

    var agent = new SyncAgent(clientProvider, serverProvider, new string[] { "Answer", "Question", "Response", 
   "ResponseType", "Site" });

    var syncContext = await agent.SynchronizeAsync(SyncType.ReinitializeWithUpload);`

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
VagueGitcommented, Apr 15, 2022

We use integer primary keys as below. This is adequate for many use cases (Google/Facebook wouldn’t do it this way).

It will usually result in less fragmentation, less disk space, faster CRUD on the server than guids/uuids.

public static Int64 NewId
{// A loop that calls DateTimeOffset.Now.UtcTicks 10 times will return 7 distinct values (3 dupes) so we check for dupes
// This method will advance ~15 UtcTicks in 10 iterations and guarantees uniqueness.
// It is almost twice as fast as a while loop with SpinWait.SpinOnce();
// So this method will return a unique value appox every 1.5 milliseconds
    get
    {
        Int64 start = DateTimeOffset.Now.UtcTicks;
        Int64 end = DateTimeOffset.Now.UtcTicks;
        while (end == start)
            end = DateTimeOffset.Now.UtcTicks;
        return end;
    }
}

I welcome constructive critique

0reactions
PeterJeycommented, Apr 16, 2022

For the moment iam using int i = Guid.NewGuid().GetHashCode();

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing Identity Columns as Primary Keys in DMS. ...
Client inserts a new record : Primary Key generated : 42; Server inserts a ... Deleted row (Primary key) on the server causes...
Read more >
How Siebel Remote Resolves Conflicts in Data It ...
If the user primary key of a new row matches the user primary key of an existing row, then Siebel Remote determines that...
Read more >
Access linked table to SQL Server database returns Deleted
When you try to commit record changes to the linked table, you may also receive the following "Write Conflict" message:.
Read more >
Locking issue with concurrent DELETE / INSERT in ...
When a READ COMMITTED transaction awakens from a block on a write conflict, it follows that update chain to the end; if the...
Read more >
Auto Increment after delete in MySQL
This record becomes orphaned from the first table. If a new record is inserted into the first table, and a sequential primary key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found