Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server Merge Replication Using An Identity Column

Posted on 2004-09-23
8
Medium Priority
?
948 Views
Last Modified: 2010-08-05
Hello,

I have set up merge replication with a pocket pc running an embedded visual basic application.  The application subscribes to our SQL Server, uses SQL Server CE, runs very well, and synchronizes with the database reliably.  

The table that I'm publishing on SQL Server is a table used to store item movements in our ERP system (i.e. stock and warehouse location changes).  The table is basically a queue for these movements and every 15 seconds it processes the movements in bulk.  

The problem is that the SQL table has an identity column.  I set my replication to automatically adjust the identity columns on the publisher and subscriber, so I have that running and no conflicts should occur.  The problem is that I have webpages updating that table, in addition to the pocket pcs, and the webpages are NOT subscribers and NOT using replication.  So my webpages often get this error...

The identity range managed by replication is full and must be updated by a replication agent. The INSERT conflict occurred in database...Sp_adjustpublisheridentityrange can be called to get a new identity range.

I tried using the Sp_adjustpublisheridentityrange store procedure before attempting an insert, but it did not correct the error.  After sometime the error does go away, however.  If I attempt the insert through the webpage, I get the error.  If I attempt the webpage insert about three times, the transaction completes.  But if all the rows are processed and removed from the table, my webpage errors everytime.

Recap...
1) Using SQL Replication on Pocket PCs running embedded VB and SQL Ce
2) Publisher is automatically adjusting identity column on subscribers and publisher
3) When webpage attempts to insert into empty table error occurs

Please help.

Thanks.
0
Comment
Question by:tomtenac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 18

Expert Comment

by:ShogunWade
ID: 12135365
you probably need to increase the number of ids allocated  in the publication or ajust the percentage before a new range is allocated, or increase the replecation frequency.
0
 

Author Comment

by:tomtenac
ID: 12135705
I have allocated the ids at  100 on both the publisher and the subscriber.

The percentage is set at 80.

But the problem occurs with minimal data entry.

For example, I enter ONE record into the table through the webpage, 15 seconds goes by, and a process will read all the records, process them, and delete the records from the table.

Now, after that record has been processed, if I enter ONE additional record into the table through the webpage, I receive the identity error.

But if I attempt and fail to insert it approximately three times through the webpage, it will succeed.

Inconceivable!!!
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 12141583
you say that " and a process will read all the records, process them, and delete the records from the table."   do you mean that essentially the web entry stuff is buffered and then batch processed ?
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:tomtenac
ID: 12141969
Correct.  The web entry and replicated records are all batched, and we have a service running that will process the records at a given interval (we have set it to 15 seconds).

I have been investigating this, though.  I think the identity range for the publisher is 4-100 or something like that, because a record will insert after three attempts without fail.  I tried, yesterday, to simply type in data into the record through enterprise manager.  When I did, it gave me the adjustpublisheridentityrange error, until the forth attempt.  On the forth attempt, the identity was set to 4.

I think what might be happening is that I may have set up replication while 3 records were in the table (so that means the next index would have been 4).

Now, I either have to reset the range or recreate the publication.  Any ideas on which means to use?
0
 
LVL 18

Accepted Solution

by:
ShogunWade earned 1500 total points
ID: 12142218
Ah ok.  Im with you now.  

Im not sure how much you know about the internals of the identity ranges so fogive me if im telling you something here you already know, but here is a brief summary of how it works.

There is a table called MSrel_identity_range in the publised database  This contains  the settings for range sizes, and next staing values for new ranges etc in it.   Its sole purpose is for ensuring that the same range isnt given out twice.   When a new identity range is issued to the publiser or the subsriber this table is looked up and subsequently updated.   In addition SQL uses standard seeded identity stuff to do the incrementing of the ids on the subsriber and publisher tables.  But in addition to this it also (as a safeguard) creates constraints to prevent overruns of the identity range currently allocated.   Thus on the publsher a constaint would exist saying that the ID must be between say 1 and 100.     Hope i havent lost you yet.

Anyway,   one problem that can occur (rarely) is that these three elements get out of step and thus conflict with each other.  It is possible to manually change all of these to bring it back in step but it is a very tedious operation.    By far the easiest thing is simply to script up your replication,  then remove it and re create it from the script.
0
 

Author Comment

by:tomtenac
ID: 12147118
I believe we have solved the problem.  I reset my publication, and made sure that no records were left in the table.  After that, I've encountered no problems inserting through the webpage and index starts at 1 instead of 4.  Brilliant!!!

Thanks,
Tom
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 12158593
your welcome.    

Its worth holding onto a script for your replication.   Ive generally found that 9 times out of 10 if replication breaks the easiest approach is to remove it and add it back again.
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12160995
>holding onto a script for your replication... if replication breaks the easiest approach is to remove it and add it back again.

I agree. But without having it scripted, it's an error-prone pain, so definitely keep the scripts.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question