About Me

My photo
I am an MCSE in Data Management and Analytics, specializing in MS SQL Server, and an MCP in Azure. With over 19+ years of experience in the IT industry, I bring expertise in data management, Azure Cloud, Data Center Migration, Infrastructure Architecture planning, as well as Virtualization and automation. I have a deep passion for driving innovation through infrastructure automation, particularly using Terraform for efficient provisioning. If you're looking for guidance on automating your infrastructure or have questions about Azure, SQL Server, or cloud migration, feel free to reach out. I often write to capture my own experiences and insights for future reference, but I hope that sharing these experiences through my blog will help others on their journey as well. Thank you for reading!

Troubleshooting The Publisher failed to allocate a new set of identity ranges for the subscription error 21197

The process could not read file 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\ReplData\unc\WIN2K12-1_ADVENTUREWORKS2014_MERGE_ADVENTUREWORKS2014_MERGE\20151029073334\Name_73.sch' due to OS error 3.




In order to resolve this issue

it seems the issue is caused by fact that

Hence in order to resolve this issue

1. get the service account of SQL Server. suppose Service account Name is adven\sqlservice.
2. go to unc folder and give full permission to folder for that service account [adven\sqlservice]
3.snapshot folder is in a local folder name on the distributor, instead of a
   UNC name. The pull merge agent running from the subscriber can not access
   the snapshot folder.
4. Change Folder name from C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\ReplData\unc to   \\Win2k12-1\C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\ReplData\unc
5. then rerun the snapshot agent.
6. Check change has been implemented or not. 





After That i started getting this error






The Publisher failed to allocate a new set of identity ranges for the subscription. This can occur when a Publisher or a republishing Subscriber has run out of identity ranges to allocate to its own Subscribers or when an identity column data type does not support an additional identity range allocation. If a republishing Subscriber has run out of identity ranges, synchronize the republishing Subscriber to obtain more identity ranges before restarting the synchronization. If a Publisher runs out of identit (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147199417)
Get help: http://help/MSSQL_REPL-2147199417
Not enough range available to allocate a new range for a subscriber. (Source: MSSQLServer, Error number: 20668)
Get help: http://help/20668
Failed to allocate new identity range. (Source: MSSQLServer, Error number: 21197)
Get help: http://help/21197







Consider the following scenario:
  • You set up a merge publication in SQL Server 2016.
  • The merge publication contains an article that has an identity column.
  • You set the Automatically manage identity ranges property for this article to Automatic.
In this scenario, when you synchronize the merge replication, the synchronization fails. Additionally, you receive the following error message:
The Publisher failed to allocate a new set of identity ranges for the subscription. This can occur when a Publisher or a republishing Subscriber has run out of identity ranges to allocate to its own Subscribers or when an identity column data type does not support an additional identity range allocation. If a republishing Subscriber has run out of identity ranges, synchronize the republishing Subscriber to obtain more identity ranges before restarting the synchronization. If a Publisher runs out of identit (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147199417)
Get help: http://help/MSSQL_REPL-2147199417
Not enough range available to allocate a new range for a subscriber. (Source: MSSQLServer, Error number: 20668)
Get help: http://help/20668
Failed to allocate new identity range. (Source: MSSQLServer, Error number: 21197)
Get help: http://help/21197
To find the cause of this error message, some technical information about how identity values are managed during replication is needed. A key source of information for table articles with identity columns is the MSmerge_identity_range table. This table contains a row for each range of values assigned to each subscriber for each article as well as an additional row holding the entire range of identity values for the table article (this is the row with is_pub_range = 1). In order to make sense of this table, the artid column can be joined to the sysmergearticles table and subid can be joined to the sysmergesubscriptions table. Take note of the max_used column (which only has a value for pub_range rows); this column holds the end of the maximum range that has been allocated for the article (technically 1-past-the-last, since it holds the max of next_range_end, but conceptually it is the end). When this value is near the end of the pub_range, then the available identity ranges are almost exhausted.One quick way to determine if the problem is due to exhaustion of the available identity range, is with a query similar to the following:SELECT name, range_begin, range_end, max_usedFROM MSmerge_identity_range mir    INNER JOIN sysmergearticles sma ON mir.artid = sma.artidWHERE is_pub_range = 1 AND range_end <= max_used + pub_rangeIf this query returns any rows, then the problem has been identified. The table articles listed have exhausted their available identity ranges. If the range_end value is below the maximum value for the identity datatype, then it should be possible to increase this value and solve the problem quite easilyor
Go to publisher database and use command:-

Use [<DatabaseName>]
go

EXEC sp_changemergearticle
@publication = N'<PublicationName>',
@article = N'<TableName>',
@property='identityrangemanagementoption',
@value = N'none',
@force_invalidate_snapshot = 1,
@force_reinit_subscription = 1;

GO

After executing this command, you will find the constraint repl_identity_range_D111A256_E756_434D_BDAA_0C0DAB941E6E] will delete automatically.

Then you Need to run

  • snapshot agent, and run the
  •  Merge agent,

Example:-

use [AdventureWorks2014_Merge]
go

EXEC sp_changemergearticle

@publication = N'AdventureWorks2014_Merge',

@article = N'ScrapReason',

@property='identityrangemanagementoption',
@value = N'none',
@force_invalidate_snapshot = 1,
@force_reinit_subscription = 1;

GO

re-run 
  • snapshot agent, and 
  •  Merge agent,

and then open replication monitor and check the issue is resolve.
otherwise repeat the same process as above for other table listed in 




SELECT name, range_begin, range_end, max_usedFROM MSmerge_identity_range mir    INNER JOIN sysmergearticles sma ON mir.artid = sma.artidWHERE is_pub_range = 1 AND range_end <= max_used + pub_range
and repeat the process until replication synchrinizing..

reference link here
http://kushagrarakesh.blogspot.com/2015/08/merge-replication-fail-with-error.html