Order ID problems

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
1. nopCommerce version: 3.5 but have had issues in everything from 2.65 on..
2. Any private modifications you made to your nopCommerce: n/a just theme
3. The version of MS SQL database you're running nopCommerce with: 2012
4. Anything else that could possibly be relevant. Err on the side of too much information, rather than too little.:  This has been going on for a few years.  The order number jumps randomly.  Below is the past year running the cart and I highlighted where it decided to skip ahead.  It seems to skip 1000 at a time..  Im using Arvixe hosting using Personal Class ASP / SSL cert / Cloudflare.  This isn't a big deal but just kind of annoying.

2335, 2336, 2337, 2338, 3338, 3339, 3340, 3341, 3342, 3343, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3357, 3358, 3359, 3360, 3361, 3362, 3363, 3364, 3365, 3366, 3367, 3368, 3369, 3370, 3371, 3372, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3405, 3406, 3407, 3408, 3409, 3410, 3411, 3412, 3413, 3414, 3415, 3416, 3417, 3418, 3419, 3420, 3421, 3422, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3433, 3434, 3435, 3436, 3437, 3438, 3439, 3440, 3441, 4441, 4442, 4443, 4444, 4445, 4446, 4447, 4448, 4449, 4450, 4451, 4452, 4453, 4454, 4455, 4456, 4457, 4458, 4459, 5459, 5460, 5461, 5462, 6462, 6463, 6464, 6465, 6466, 6467, 6468, 6469, 6470, 6471, 6472, 6473, 6474, 6475, 6476, 6477, 6478, 6479, 6480, 6481, 6482, 6483, 6484, 6485, 6486, 6487, 6488, 7485, 7486, 7487, 7488, 7489, 7490, 7491, 7492, 7493, 8493, 8494, 9494, 9495, 9496, 9497, 9498, 9499, 9500, 9501, 9502, 9503, 9504, 9505, 9506, 9507, 10507, 10508, 10509, 10510, 10511, 10512, 10513, 10514, 10515, 10516, 10517, 11517, 11518, 11519, 11520, 11521, 11522, 11523, 11524, 11525, 11526, 11527, 11528, 11529, 11530, 11531, 11532, 11533, 11534, 11535, 11536, 11537, 11538, 11539, 11540, 11541, 11542, 11543, 11544, 11545, 11546, 11547, 11548, 11549, 11550, 11551, 11552, 11553
8 years ago
It's a bug in SQL server 2012. It happens when SQL server 2012 looses its pre-allocated sequence numbers.
http://stackoverflow.com/questions/18103908/identity-column-increment-jump
7 years ago
I use the sp_FixSeeds2012 workaround from
https://connect.microsoft.com/SQLServer/feedback/details/739013/alwayson-failover-results-in-reseed-of-identity

I made some fixes on the script.
Avoiding checking viewes and a fix for databases containing dot.(ex:database.1)
See below the fixed script.




USE [master]
GO
/****** Object:  StoredProcedure [dbo].[sp_FixSeeds2012]    Script Date: 06/18/2016 21:51:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_FixSeeds2012]
AS
BEGIN

    --foreach database
    DECLARE @DatabaseName varchar(255)
    
    DECLARE DatabasesCursor CURSOR READ_ONLY
    FOR
        SELECT name
        FROM sys.databases
        where name not in ('master','tempdb','model','msdb') and sys.databases.state_desc = 'online'

    OPEN DatabasesCursor

    FETCH NEXT FROM DatabasesCursor
    INTO @DatabaseName

    WHILE @@FETCH_STATUS = 0
    BEGIN
    
        EXEC ('USE ['+@DatabaseName + ']

        --foreach identity column
        DECLARE @tableName varchar(255)
        DECLARE @columnName varchar(255)
        DECLARE @schemaName varchar(255)
      
        DECLARE IdentityColumnCursor CURSOR READ_ONLY
        FOR
        
      SELECT
        TABLE_NAME =t.name,
        COLUMN_NAME =c.name,
        TABLE_SCHEMA = s.name
      FROM
        sys.schemas AS s
        INNER JOIN sys.tables AS t ON s.schema_id = t.schema_id
        INNER JOIN sys.columns AS c ON t.object_id = c.object_id
        INNER JOIN sys.identity_columns AS ic on c.object_id = ic.object_id AND c.column_id = ic.column_id
      GROUP BY
        s.name,
        t.name,
        c.name
            

        OPEN IdentityColumnCursor

        FETCH NEXT FROM IdentityColumnCursor
        INTO @tableName, @columnName, @schemaName

        WHILE @@FETCH_STATUS = 0
        BEGIN
        
            print ''['+@DatabaseName+'].[''+@tableName+''].[''+@schemaName+''].[''+@columnName+'']''  
            EXEC (''declare @MAX int = 0
                    select @MAX = max(''+@columnName+'') from ['+@DatabaseName+'].[''+@schemaName+''].[''+@tableName+'']
                    if (@MAX IS NULL)
                    BEGIN
                        SET @MAX = 0
                    END
          IF ('''''+@DatabaseName+''''' LIKE ''''%.%'''')
            BEGIN
              DBCC CHECKIDENT([''+@schemaName+''.''+@tableName+''],RESEED,@MAX)
            END
                    ELSE
            BEGIN
              DBCC CHECKIDENT(['+@DatabaseName+'.''+@schemaName+''.''+@tableName+''],RESEED,@MAX)
            END
                    '')

            FETCH NEXT FROM IdentityColumnCursor
            INTO @tableName, @columnName, @schemaName

        END

        CLOSE IdentityColumnCursor
        DEALLOCATE IdentityColumnCursor')

        FETCH NEXT FROM DatabasesCursor
        INTO @DatabaseName

    END

    CLOSE DatabasesCursor
    DEALLOCATE DatabasesCursor
END



EXEC sp_procoption @ProcName = 'sp_FixSeeds2012'
    , @OptionName = 'startup'
    , @OptionValue = 'true'
GO

7 years ago
I use SQL server 2014 web, and my order number also jumped from 3269 - 4269
7 years ago
I did this on my SQL server

http://big.info/2013/01/how-to-solve-sql-server-2012-identity.html
7 years ago
I have tried adding startup parameter "-T272" and It did not work for me on Sql Server 2012.
7 years ago
Further fix on
sp_FixSeeds2012
workaround.
Added
 WHERE last_value IS NOT NULL 
in order to exclude new tables if no rows have been inserted  since it was created.

This inconsistent behavior is by design – it has been documented in MSDN:
https://msdn.microsoft.com/en-us/library/aa258817


      SELECT
        TABLE_NAME =t.name,
        COLUMN_NAME =c.name,
        TABLE_SCHEMA = s.name
      FROM
        sys.schemas AS s
        INNER JOIN sys.tables AS t ON s.schema_id = t.schema_id
        INNER JOIN sys.columns AS c ON t.object_id = c.object_id
        INNER JOIN sys.identity_columns AS ic on c.object_id = ic.object_id AND c.column_id = ic.column_id
      WHERE last_value IS NOT NULL
      GROUP BY
        s.name,
        t.name,
        c.name


Adding lowercase startup parameter "-t272" works on some cases too.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.