all groups > sql server replication > june 2004 >
You're in the

sql server replication

group:

stored procedure custom resolver question


stored procedure custom resolver question news.microsoft.com
6/29/2004 4:42:20 PM
sql server replication: I've looked at the avgprice example for northwind but don't understand what
would happen if the conflict occured because of a delete. I'd like to
create a resolver that the subscriber always wins the update unless the row
was deleted at the publisher.

TIA

Re: stored procedure custom resolver question news.microsoft.com
6/30/2004 8:13:35 AM
Then why do I get these type of messages in the conflict resolver?

The same row was updated at 'LAPTOP.DB' and deleted at 'SERVER.DB'. The
resolver chose the update as the winner.



[quoted text, click to view]

Re: stored procedure custom resolver question news.microsoft.com
6/30/2004 8:26:50 AM
If my first post wasn't clear, what I am trying to accomplish is to have the
subscriber always win conflicts unless the publisher deleted the row. In
that case I want that row deleted regardless of what happened to the row on
the subscriber. There is a column that almost always gets updated on the
subscriber but never on the publisher so it never causes conflicts, but
since the resolution is currently set to 'subscriber always wins' the
deletes at the publisher cause a conflict with the update are never allowed
to propogate to the subscriber.



[quoted text, click to view]

Re: stored procedure custom resolver question Paul Ibison
6/30/2004 9:11:32 AM
The problem is that if the row was deleted at the publisher, there wouldn't
be a conflict - a conflict implies concurrent updates.
If the row was deleted at the publisher, ideally what would you want to
occur? Normally a delete is replicated as a delete, regardless of the
conflict resolution mechanism chosen.
HTH,
Paul Ibison

Re: stored procedure custom resolver question news.microsoft.com
6/30/2004 9:15:56 AM
I'm not sure. I'm currently using the built-in 'Microsoft SQL Server
Subscriber Always Wins Conflict Resolver'

Those messages are returned in the results of sp_helpmergedeleteconflictrows

[quoted text, click to view]

Re: stored procedure custom resolver question news.microsoft.com
6/30/2004 2:59:27 PM
I wrote a stored procedure that works. I tested it with two 2K servers, now
I need to test with SQL CE.

Thanks for your help.

Here is my code.

-- this resolver forces subscriber to win but allows deletes to have
precidence over updates
--
-- NB: the 'Microsoft SQL Server Subscriber Always Wins Conflict Resolver'
lets updates
-- to the subscriber to win over deletes on the publisher

CREATE PROC sp_sub_wins_resolver
@tableowner sysname,
@tablename sysname,
@rowguid uniqueidentifier,
@subscriber sysname,
@subscriber_db sysname,
@log_conflict int OUTPUT,
@conflict_message nvarchar(512) OUTPUT
AS
DECLARE
@sub_qualified_name NVARCHAR(392),
@select_string NVARCHAR(2000)

-- generate query that will return the conflicting subscriber row
SELECT
@sub_qualified_name=QUOTENAME(@subscriber)+'.'+QUOTENAME(@subscriber_db)+'.'
+QUOTENAME('dbo')+'.'+QUOTENAME(@tablename)
SELECT @select_string='SELECT * FROM ' + @sub_qualified_name + ' WHERE
rowguid = ''' + convert(nchar(36),@rowguid) + ''''

-- return row from subscriber as winner
exec sp_executesql @select_string

-- log publisher lost conflict
RETURN(2)
GO




[quoted text, click to view]

Re: stored procedure custom resolver question Paul Ibison
6/30/2004 4:41:56 PM
Is this error message received from the custom resolver?
My understanding is that SQL Server stored procedure resolvers will be
invoked only to handle update conflicts.
Regards,
Paul Ibison

Re: stored procedure custom resolver question Paul Ibison
6/30/2004 8:48:21 PM
OK, then if you want a resolver (custom) that deals with both deletes and
updates then have a look at the C++ sample. I haven't used it but I'm pretty
sure that the custom stored procedure resolver only applies to update
conflicts.
HTH,
Paul Ibison

Re: stored procedure custom resolver question Paul Ibison
7/1/2004 12:54:16 PM
Nice!
I suspect that this resolver is only called on update conflicts and the
default rule that deletes always win handles the other case for you.
Thanks for the update and the script.
Regards,
Paul Ibison

Re: stored procedure custom resolver question anonymous NO[at]SPAM discussions.microsoft.com
7/30/2004 8:28:33 AM
You dont do a "Return(2)". Instead, set the
@Log_Conflict = 2. Then do a Return(0).

[quoted text, click to view]
AddThis Social Bookmark Button