Solved

SQL Server Merge Replication Using An Identity Column

Posted on 2004-09-23
8
927 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
  • 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
 

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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 18

Accepted Solution

by:
ShogunWade earned 500 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now