Solved

SQL Server Merge Replication Using An Identity Column

Posted on 2004-09-23
8
924 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 18

Accepted Solution

by:
ShogunWade earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

772 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

12 Experts available now in Live!

Get 1:1 Help Now