Solved

SQL Server Merge Replication Using An Identity Column

Posted on 2004-09-23
8
933 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

762 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