Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

FOREIGN KEY problem in merge replication

 
   Database Help (Home) -> Replication RSS
Next:  Change text from lower case to upper case in Acce..  
Author Message
Zaza Turmanidze

External


Since: Dec 29, 2008
Posts: 8



(Msg. 1) Posted: Mon Dec 29, 2008 10:22 pm
Post subject: FOREIGN KEY problem in merge replication
Archived from groups: microsoft>public>sqlserver>replication (more info?)

Hi,
In SQL 2008 with merge replication I have “A1” table on a publisher database
and synchronization works fine to subscriber database. Then I added new
table “B1” and FOREIGN KEY “FK_ToB1” in “A1” to “B1” table and run this
script

EXEC sp_addmergearticle
@publication = 'Publ2008',
@article = 'B1',
@source_object = 'B1',
@identityrangemanagementoption = N'auto',
@processing_order = 5,
@pub_identity_range = 100000,
@identity_range = 100000,
@threshold = 80,
@schema_option = 0x0004FF1,
@force_invalidate_snapshot = 1,
@verify_resolver_signature = 0

After this action, synchronization goes on error:
([distribution].[dbo].[MSrepl_errors])
1.
The schema script ' if object_id(N'[dbo].[ FK_ToB1]') is null if
object_id(N'[dbo].[A1]') is not null exec('ALTER TABLE [dbo].[A1] ADD
CONSTRAINT [FK_ToB1] FOREIGN KEY ([B1_ID]) REFERENCES [B1] ([B1_ID])')' could
not be propagated to the subscriber.
2.
Foreign key ' FK_ToB1' references invalid table 'B1'.
3.
Could not create constraint. See previous errors.

It seems that synchronization first moves A1 table with FOREIGN KEY, in
spite off that A1 table has @processing_order = 10 and B1 has
@processing_order = 5

Any help would be greatly appreciated.

Zaza Turmanidze

 >> Stay informed about: FOREIGN KEY problem in merge replication 
Back to top
Login to vote
Paul Ibison

External


Since: Oct 03, 2008
Posts: 145



(Msg. 2) Posted: Tue Dec 30, 2008 1:20 am
Post subject: RE: FOREIGN KEY problem in merge replication [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

If A1 and B1 are related through DRI on the publisher then you shouldn't need
to get involved with processing order - it'll determine the order directly
from the DRI. Have you tries without setting the @processing_order?
HTH,
Paul Ibison

 >> Stay informed about: FOREIGN KEY problem in merge replication 
Back to top
Login to vote
Zaza Turmanidze

External


Since: Dec 29, 2008
Posts: 8



(Msg. 3) Posted: Tue Dec 30, 2008 2:24 am
Post subject: RE: FOREIGN KEY problem in merge replication [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Paul
Yes of course. My first try was adding articles without @processing_order.
A1 and B1 are related through DRI on the publisher but... Sad
Any idea?

"Paul Ibison" wrote:

> If A1 and B1 are related through DRI on the publisher then you shouldn't need
> to get involved with processing order - it'll determine the order directly
> from the DRI. Have you tries without setting the @processing_order?
> HTH,
> Paul Ibison
>
>
 >> Stay informed about: FOREIGN KEY problem in merge replication 
Back to top
Login to vote
Zaza Turmanidze

External


Since: Dec 29, 2008
Posts: 8



(Msg. 4) Posted: Tue Dec 30, 2008 2:53 am
Post subject: RE: FOREIGN KEY problem in merge replication [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Back to top
Login to vote
Paul Ibison

External


Since: Oct 03, 2008
Posts: 145



(Msg. 5) Posted: Tue Dec 30, 2008 3:27 am
Post subject: RE: FOREIGN KEY problem in merge replication [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

There's something very wrong here because the DRI scripts are applied after
the schema scripts when initializing. Perhaps it is something to do with the
schema of the table? Is the table created, but under a different schema to
the one used in the FK script. Please can you post up scripts for the 2
tables so I can reproduce. Also I didn't verify - are you adding this article
separately and initializing it on its own, or is this part of a
reinitialization?
HTH,
Paul Ibison
 >> Stay informed about: FOREIGN KEY problem in merge replication 
Back to top
Login to vote
Zaza Turmanidze

External


Since: Dec 29, 2008
Posts: 8



(Msg. 6) Posted: Tue Dec 30, 2008 4:43 am
Post subject: RE: FOREIGN KEY problem in merge replication [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Follow this steps.
1) Make merge replication with push subscription
2) Make a snapshot
3) Create subscriber database
4) Start synchronization
5) Create table "A" in a publisher. (scripts)

a) "CREATE TABLE [A] ( [AID] int NOT NULL IDENTITY (1, 1))"
b) "ALTER TABLE [A] ADD CONSTRAINT [Pk_AID] PRIMARY KEY ([AID])"

6) Run sp_addmergearticle (scripts)

EXEC sp_addmergearticle
@publication = 'Publ2008',
@article = 'A',
@source_object = 'A',
@identityrangemanagementoption = N'auto',
@pub_identity_range = 100000,
@identity_range = 100000,
@threshold = 80,
@schema_option = 0x0004FF1,
@force_invalidate_snapshot = 1,
@verify_resolver_signature = 0

7) Generate snapshot again
Cool Start synchronization
9) Check if "A" table uploaded to subscriber. if succeed
10) Create table "B" in a publisher. (scripts)
a) "CREATE TABLE [B] ( [BID] int NOT NULL IDENTITY (1, 1))"
b) "ALTER TABLE [B] ADD CONSTRAINT [Pk_BID] PRIMARY KEY ([BID])"

11) Run sp_addmergearticle (scripts)

EXEC sp_addmergearticle
@publication = 'Publ2008',
@article = 'B',
@source_object = 'B',
@identityrangemanagementoption = N'auto',
@pub_identity_range = 100000,
@identity_range = 100000,
@threshold = 80,
@schema_option = 0x0004FF1,
@force_invalidate_snapshot = 1,
@verify_resolver_signature = 0

12) Add column to "A" (scripts)
"sp_repladdcolumn @source_object = '[A]', @column = 'BID' , @typetext =
'INT NULL'"

13) Add FK to "A" table (scripts)
"ALTER TABLE [A] ADD CONSTRAINT [FK_A_B_BID] FOREIGN KEY ([BID]) REFERENCES
[B] ([BID])"

14) Generate snapshot again
15) Start synchronization

Hopefully You must get errors.


"Paul Ibison" wrote:

> There's something very wrong here because the DRI scripts are applied after
> the schema scripts when initializing. Perhaps it is something to do with the
> schema of the table? Is the table created, but under a different schema to
> the one used in the FK script. Please can you post up scripts for the 2
> tables so I can reproduce. Also I didn't verify - are you adding this article
> separately and initializing it on its own, or is this part of a
> reinitialization?
> HTH,
> Paul Ibison
 >> Stay informed about: FOREIGN KEY problem in merge replication 
Back to top
Login to vote
Paul Ibison

External


Since: Oct 03, 2008
Posts: 145



(Msg. 7) Posted: Tue Dec 30, 2008 5:22 am
Post subject: RE: FOREIGN KEY problem in merge replication [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

OK - there's a few extra steps here you didn't mention Wink.
Please have a look at Mike Hotek's article :
http://www.mssqlserver.com/replication/alert_merge_ddl.asp
HTH,
Paul Ibison
 >> Stay informed about: FOREIGN KEY problem in merge replication 
Back to top
Login to vote
Zaza Turmanidze

External


Since: Dec 29, 2008
Posts: 8



(Msg. 8) Posted: Wed Jan 21, 2009 10:12 pm
Post subject: RE: FOREIGN KEY problem in merge replication [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Paul,
Sorry I was on leave and could not reply you.
When I read Mike Hotek's article, I decided to solve my problem by simple
way and need your suggestion. May be it's not correct, but my head already
overheated and can't find other right solution Smile
As I guess the problem is that the Foreigh key creation DDL changes record
inserts in "sysmergeschemachange" table first. I decide to collect
"sysmergeschemachange" table record ID's with schematype=300 after Foreign
key creation, and after snapshot regeneration update schemaversion field
(increase by max value) by my previously collected record ID's.
What about my ugly solution? Wink
I'd like to know your opinion about this solution.

Zaza Turmanidze
 >> Stay informed about: FOREIGN KEY problem in merge replication 
Back to top
Login to vote
Paul Ibison

External


Since: Oct 03, 2008
Posts: 145



(Msg. 9) Posted: Fri Jan 23, 2009 4:10 am
Post subject: RE: FOREIGN KEY problem in merge replication [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

This might work - can't check out the ramifications right now - but the
problem with solutions like this is that they can lead you to an unsupported
setup. Better to sync up after adding the column and then make the DRI
change. Of course if you're already in this predicament this advice doesn't
really help. In that case I'd probably reinitialize, after using DataCompare
to get any changed made at the subscriber (hopefully there's only one).
HTH,
Paul Ibison, www.replicationanswers.com
 >> Stay informed about: FOREIGN KEY problem in merge replication 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Merge Replication nested view replication problem - I am using SQL 2005 as pub and SQL EXPRESS as sub with Merge replication. Got the following error message The schema script 'CD_InTransit_v_153.sch' could not be propagated to the subscriber. Error Detail: The schema script 'CD_InTransit_v_153.sch'..

problem with merge replication - Hi, I ran an update query on the publisher. When I start the merge agent manually, I got the following error after a while. The merge process failed to execute a query because the query timed out. If this failure continues, increase the query timeout....

Merge replication problem - Hi I am running merge replication between 2 SQL 2005 Standard SP2 servers. On the publisher, in replication monitor I get an error occuring. The error is frequent but not consistently happening so the remainder of the time the replication process run...

Merge Replication problem - I have created a publisher on one SQL Server 2000 box for a merge replication. When I create the subscription, I receive the following error: Message The schema script '\\NVIS\$SQLDATA$xxxxxxx_1.sch' could not be propagated to the subscriber. The..

Urgent, problem with merge replication - Hi, So this is where we are at. I am having some weird problems with conflicts after a failed server move yesterday. Currently we have a publisher call RCK1 and a subscriber called DC3. Yesterday I attempted to move the publisher from RCK1 to MOV10. I....
   Database Help (Home) -> Replication All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]