Solved

autoincrement identity problem with merge replication sql server 2005

Posted on 2009-07-05
7
512 Views
Last Modified: 2012-05-07
I have a system that comprises two MS Sql server database servers with merge replication configured.
The publisher publishes a table that has a primary key of type integer that is an identity columne with a seed of 1 and an increment of 1.
All data updates are performed at the subscriber under normal circumstances.
Periodic archiving results in the deletion of records from the publisher and the replication functions as expected, resulting in the same deletions at the subscriber database.
An incident occurred which required taking the publisher off line and continueing with the subscriber database for a short period. primary key did not continue with the expected values that would follow on (autoincremented) from the records in the publisher database. Instead, the values continued from a lower value as if the system was attempting to fill in the numbers that had been previously deleted.
This poses a problem due to the loss of referential integrity.
Goe can i configure the publisher/subscriber so that the auto-incremented columne in the table continues contigiously regardless.

Thanks,

Roger
when new records were added to the subscriber tale however, it was observed that the
0
Comment
Question by:alcindor
  • 4
  • 2
7 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24781872
I have read about this problem somewhere.

And to resolve this problem its expected to have Identity(1,2) in your First Server and Identity(2,2) in your second server so that this would be unique and you will not face referential integrity issues.

Will check for that article or reference and provide you the reference soon.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24783336
when in replication, the only "secure" primary key method is the use of uniqueidentifiers. they are globally unique
will require some application changes, though :/(
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24783678
alcindor,
    I found the document reference and it was from a third party application involved in Replication methodologies and I cannot share their proprietary document here.

Whatever I mentioned above applies and you have to make it as Identity(1,2) in first server and Identity(2,2) in second server to handle out this issue.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

by:alcindor
ID: 24784896
Thanks for your reply guys.
I was already aware of the your suggestion (1,2) and (2,2) but in this case it is not a practical option at this stage.
In this instance, the subscriber database is acting purely as a backup device that can be switched to if an emergency arises which requires the publisher to go off line. The subscriber then functions temporarily until the publisher can be placed back on line.
At any one time, the system is either writing data to the publisher or (after the publisher has been taken off line) the system is writing data to the subscriber. At no time whist both publisher and subscriber are on line does data get written to both servers.
When the publisher is taken off line, the subscriber is up to date with the most recent identity that was generated by the publisher. the problem is that even though the most recent identity in the subscriber matches that of the publisher, when the next record is generated by the subscriber it generates an identity that is not the incremented value of the current highest identity but some value considerable lower.
There must be a value stored in the subscibers configuration somewhere that the system uses to calculate the next identity? If I knew where this was then I could conceivably set it to the required value and the subscriber would function as required? I am not in a position to adopt the suggestion that you recommend at the moment, I seek the information mentioned above; namely "where is the information kept that determines the next value of the Identity for any particular table such that I can change it?

Thanks in anticipation,

Roger

 
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 24785555
>> where is the information kept that determines the next value of the Identity for any particular table such that I can change it?

Then IDENT_CURRENT( 'table_name' ) should help you out.

IDENT_CURRENT( 'table_name' ) Returns the last identity value generated for a specified table or view in any session and any scope.

Hence the next value would be IDENT_CURRENT( 'table_name' ) + 1 / x where x represents the increment value for each and every identity column.

Once you identify the next value, then you have to apply DBCC CHECKIDENT to reseed the values like

DBCC CHECKIDENT ('table_name', RESEED, y)
where y = IDENT_CURRENT( 'table_name' ) + 1 / x

Hope this helps
0
 
LVL 2

Author Closing Comment

by:alcindor
ID: 31599966
Excellent!
That is exactly what I needed to know, I( will not be able to implement it for a few days but I'm confident that I have the information neccessary to do what I need.

Many thanks,
Roger
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24790319
Thanks and Glad to help you.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

19 Experts available now in Live!

Get 1:1 Help Now