9

I'm building a basic CRUD page following beginner asp.net-core-mvc/ef-core tutorials

I've been noticing every time I rebuild and create a new record through my mvc site my Id's jump up 1000

Example, currently the id's for my first few rows are:

  • 1, 2, 1002, 1003, 1004, 2002, 2003, 3002, 3003, 4002, 5002

How do I stop this? I've never seen this behavior before. From some googling it seems to be a sql 2012 issue however I'm not using sql 2012.

I'm using mssqllocaldb, everything's updated and I have SSMS2014 installed

Sampath
  • 63,341
  • 64
  • 307
  • 441
mejobloggs
  • 7,937
  • 6
  • 32
  • 39
  • Possible duplicate of [Identity increment is jumping in SQL Server database](http://stackoverflow.com/questions/14146148/identity-increment-is-jumping-in-sql-server-database) – Shyju Sep 24 '16 at 04:34
  • https://github.com/aspnet/EntityFrameworkCore/issues/8252 – juFo Mar 04 '19 at 09:42

1 Answers1

6

Even though you have installed the SSMS 2014, it doesn't install the 2014 local db instance. It still can be a SQL 2012 local DB. So my advice is to uninstall all old components and install the latest local db 2016 and SSMS 2016. Both are free.

Here are the links :

SQL Server 2016 Express LocalDB

SSMS 2016

Additional Note :

Yes this is a bug on the SQL server 2012.You can see it here :

Failover or Restart Results in Reseed of Identity

Workarounds :

If you need the Workarounds see the Workarounds tab on the above link.

enter image description here

Permanent solution :

If you need a permanent solution, you can use a higher version of SQL server. Like SQL server 2014 or 2016.You can select Free community editions of those.

spottedmahn
  • 14,823
  • 13
  • 108
  • 178
Sampath
  • 63,341
  • 64
  • 307
  • 441
  • 1
    I'm not using SQL 2012. I'm using mssqllocaldb. I'm not sure what determines the version of localdb, but i have Sql Data Tools fully updated and Sql Management Studio 2014 installed, so my mssqllocaldb should be using newer than 2012 – mejobloggs Sep 24 '16 at 03:05
  • what is the version of `mssqllocaldb` ? – Sampath Sep 24 '16 at 03:06
  • how do i check the version? – mejobloggs Sep 24 '16 at 03:07
  • please see this : https://msdn.microsoft.com/en-us/library/hh215237.aspx – Sampath Sep 24 '16 at 03:10
  • 2
    Finally got it thanks. Yes the root cause was SQL 2012 even though I already had 2014/2016 installed. Ended up having to manually uninstall all references to sql 2012 and do a repair of sql 2016 and a repair of VS2015 before it worked. – mejobloggs Sep 24 '16 at 05:22
  • WHen I try to uninstall SQL Server 2012 Native Client, it says SQL Server 2016 LocalDB depends on it. :( Uninstall Anyway? I don't have SQL 2012 LocalDB at all, would this still be the root cause in my case? – CularBytes May 25 '18 at 14:19