Showing posts with label filter. Show all posts
Showing posts with label filter. Show all posts

Wednesday, March 28, 2012

Merge Replication with vertical Filters

Hello
it's possible to create a Merge-Publication with vertical Filter on an
Sql-Server 2000 with SP3?
in our developer System with SP4 i can make a replication, but in the Target
System i didn't.
Error 20009 add the article...
Thanks
Daniel
Yes it is, but ensure that you have defaults in place for the columns you
are not replicating or that they are nullable.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Dani Schwegler" <d.schwegler@.hispeed.ch> wrote in message
news:ezRNYPmUGHA.4956@.TK2MSFTNGP09.phx.gbl...
> Hello
> it's possible to create a Merge-Publication with vertical Filter on an
> Sql-Server 2000 with SP3?
> in our developer System with SP4 i can make a replication, but in the
> Target System i didn't.
> Error 20009 add the article...
> Thanks
> Daniel
>
sql

Merge replication with dynamic filter

Brand new to SQL Server 2005 and replication, I was able to use online books info to get a replication topology set up (using wizards) and successfully replicate an article (a single table) to a SQL Server Express database.

I then cleared the subscription table and added a simple dynamic filter (colx = SUSER_SNAME()), which I can't get to work. Based on what I read, I'm thinking that SUSER_SNAME() is not returning the proper value because the merge agent is set to connect to the publisher and distributor by 'impersonating the process account'. This is on the subscription merge agent security form. However, 'using a SQL Server login' is greyed out and nothing I tried will enable it, including setting up logins and SQL user ids on the publisher and playing with entries on the publication properties data partitions page, etc.

I think that I have discovered only some of the pieces that I need and not enough details to find the rest and put them together. Any info on what to have set up where would be appreciated. Any suggestions for 'step by step' information that would help in addition to SQL Server 2005 Books Online would be great.

Thanks in advance.

SUSER_NAME is the account that replication connects to the publisher with. You can override it with the -PublisherLogon property. By chance is this subscriber SQL Server Express? There are some limitations of SQL Server Express with replication, and I suspect that you are bumping into one of them. -- Hilary Cotter Director of Text Mining and Database Strategy RelevantNOISE.Com - Dedicated to mining blogs for business intelligence. This posting is my own and doesn't necessarily represent RelevantNoise's positions, strategies or opinions. Looking for a SQL Server replication book? http://www.nwsu.com/0974973602.html Looking for a FAQ on Indexing Services/SQL FTS http://www.indexserverfaq.com wrote in message news:740eab10-6268-4aff-9dc9-56651ebc9d3d@.discussions.microsoft.com... Brand new to SQL Server 2005 and replication, I was able to use online books info to get a replication topology set up (using wizards) and successfully replicate an article (a single table) to a SQL Server Express database. I then cleared the subscription table and added a simple dynamic filter (colx = SUSER_SNAME()), which I can't get to work. Based on what I read, I'm thinking that SUSER_SNAME() is not returning the proper value because the merge agent is set to connect to the publisher and distributor by 'impersonating the process account'. This is on the subscription merge agent security form. However, 'using a SQL Server login' is greyed out and nothing I tried will enable it, including setting up logins and SQL user ids on the publisher and playing with entries on the publication properties data partitions page, etc. I think that I have discovered only some of the pieces that I need and not enough details to find the rest and put them together. Any info on what to have set up where would be appreciated. Any suggestions for 'step by step' information that would help in addition to SQL Server 2005 Books Online would be great. Thanks in advance.|||Yes, the subscriber is on SQL Express. In the mean time, I am trying to get it to work with HOST_NAME(). That doesn't seem to have the login/user/rights issues that SUSER_SNAME() does?|||You could override the -HostName parameter with what you normally use for the SUSER_NAME. For example if you want to filter on users, you could use a -HostName parameter of Fred. -- Hilary Cotter Director of Text Mining and Database Strategy RelevantNOISE.Com - Dedicated to mining blogs for business intelligence. This posting is my own and doesn't necessarily represent RelevantNoise's positions, strategies or opinions. Looking for a SQL Server replication book? http://www.nwsu.com/0974973602.html Looking for a FAQ on Indexing Services/SQL FTS http://www.indexserverfaq.com wrote in message news:927b07a9-77e7-4a97-b7f5-14f5f9b9a496@.discussions.microsoft.com... Yes, the subscriber is on SQL Express. In the mean time, I am trying to get it to work with HOST_NAME(). That doesn't seem to have the login/user/rights issues that SUSER_SNAME() does?|||

There are three situations related to your scenario:

1. if the merge subscription is push, there is a known Yukon bug, which tells there is no way to input a SQL Authentication user to login in Publisher/Distributor. Please refer to the below description of the bug.

In dynamic filter merge pub, if filter is like SUSER_SNAME(), and SUSER_SNAME is a SQL user, there is no way to input a SQL Authentication user to connect Pub/Dist in Merge Agent Security Page of CreateSub wizard.

For push sub, Publisherlogin and DistributorLogin can only be process account in UI.

2. If merge subscription is pull. It will be fine.

3. If subscriber is based on SQL Express and merge subscription is pull, it won't be supported. Since SQL Express doesn't support Merge agent at all, sync can only be done through Windowns Synchronization.

Hope the above information will help.

-Yunjing

|||

I got rid of everything that I had and started over this time using HOST_NAME(). Everything went smoothly and it worked the first time!

I'm not sure why the MS online books appear to focus on SUSER_SNAME() and mention HOST_NAME(). The use of SUSER_SNAME() looks to be way more complicated in accomplishing the same thing despite the bug mentioned.

Thanks for helping a new guy get going. The merge replication tool with filtering is going to save a bunch of additional application development.

|||

It's glad to see your scenario worked. SUSER_SNAME() is used more often than HOST_NAME(), since it can implement partitional filtering for different user instead of for different machine. The bug I mentioned is only for configuration through UI, if replication is set up through SP, everything still works fine.

Hope these information will help as well.

Thanks

Yunjing

Monday, March 26, 2012

Merge Replication using a guid as a dynamic filter

Hi ...

I am working on a project where the server version of application has vouchers from different entities. I have created a publication manually. My next step was to create a client subscription using rmo and to execute a pull. This part works fine. Code samples from http://msdn2.microsoft.com/en-us/library/ms147314.aspx

My next step would be to implement dynamic filtering using the guid of the entity as a parameter.

I dont want to use suser_sname() or host_name() as I want to use a fixed login for the replication for all users, and a client could have several host dbs (sql express, sql mobile)

My goal would be to pass a guid-value to the HostName Property of the MergePullSubscription class and convert it to an uniquidentifier and use it as a filter as I have not found any other way to pass a guid as a filter.

RMO-Code:

subscription.HostName = "4bb0e468-c68a-4253-ba82-f71c3a6e302d"

Filter:

SELECT <published_columns> FROM [dbo].[voucher] WHERE [entity_ID] = dbo.fx_ConvertHostToEntity()

Function:

create function fx_ConvertHostToEntity()
returns uniqueidentifier
as
Begin
declare @.host nvarchar(50)
set @.host = host_name()
declare @.entity uniqueidentifier
set @.entity = cast( @.host as uniqueidentifier)
return @.entity
End

When trying to set the filter sql server complains that a character string cannot be casted to a uniqueidentifier - so i can not set this filter. Is there a way to pass a parameter other then the username or the hostname as a filter?

SELECT <published_columns> FROM [dbo].[voucher] WHERE [entity_ID] =@.entity, where @.entity is a guid

Thanks for your support

Alex

Hi, Alex,

You can convert the string to binary then to uniqueidentifier, like following:

declare @.host nvarchar(50)
set @.host = host_name()
declare @.entity uniqueidentifier
set @.entity = cast( convert(varbinary, @.host) as uniqueidentifier)
print @.entity

Output:


00450044-004C-004C-3000-340032003700

Thanks,

Zhiqiang Feng

|||

Thanks for the info changed the function according to your suggestion.

Now a new problem arrises: I receive 0 rows for the filtered tables. When changing the funktion to

ALTER FUNCTION [dbo].[fx_ConvertHostToEntity] ()
returns uniqueidentifier
as
Begin
declare @.host nvarchar(50)
set @.host = host_name()
declare @.entity uniqueidentifier
set @.entity = cast( convert(varbinary, @.host) as uniqueidentifier)
-- return @.entity
return '4bb0e468-c68a-4253-ba82-f71c3a6e302d'
End

I get the rows in the replicated table. So the problem must be somewhere either in the creation of the sanpshots or the resolution of the hostname

|||

Using Replication Monitor for the publication I also found out using the properties of the publication that the snapshot for the data partition has not been created. So I did this manually and will code it later on. When replicating again I got the follwowing error shown up in the Replication Monitor (I left out the first one as I am not using web sync right now):

Partitioned snapshot validation failed for this Subscriber. The snapshot validation token stored in the specified partitioned snapshot location does not match the value '{00620034-0062-0030-6500-340036003800}' used by the Merge Agent when evaluating the parameterized filter function. If specifying the location of the partitioned snapshot (using -DynamicSnapshotLocation), you must ensure that the snapshot files in that directory belong to the correct partition or allow the Merge Agent to automatically detec (Source: MSSQL_REPL, Error number: MSSQL_REPL27223)

Find the full source code below:

Imports Microsoft.SqlServer.Replication

Imports Microsoft.SqlServer.Management.Common

Public Class Replication

Private subscriberName As String

Private publisherName As String

Private windowsLogin As String

Private windowsPWD As String

Private publicationName As String

Private publicationDbName As String

Private subscriptionDbName As String

Private passedHostname As String

''' <summary>

''' a new instance of the replication object

''' </summary>

''' <param name="EntityID">id of the entity as string</param>

''' <param name="SubscriberHost">the hostname of the subscribing sql instance</param>

''' <param name="PublisherHost">the hostname of the publishing sql instance</param>

''' <param name="Login">the name of the windows login to authenticate towards the publisher: domain\user</param>

''' <param name="PWD">the password</param>

''' <param name="Publication">the name of the puplicaiton on the publisher</param>

''' <param name="PublicationDB">the name of the puplication db</param>

''' <param name="SubscriptionDB">the name of the subscription db</param>

''' <remarks></remarks>

Sub New(ByVal EntityID As Guid, ByVal SubscriberHost As String, ByVal PublisherHost As String, ByVal Login As String, ByVal PWD As String, ByVal Publication As String, ByVal PublicationDB As String, ByVal SubscriptionDB As String)

subscriberName = SubscriberHost

publisherName = PublisherHost

'the guid of the entity is passed as hostname to be used for filtering

PassedHostname = EntityID.ToString

windowsLogin = Login

windowsPWD = PWD

publicationName = Publication

subscriptionDbName = SubscriptionDB

publicationDbName = PublicationDB

End Sub

Sub SetupPullSubscription()

'Create connections to the Publisher and Subscriber.

Dim subscriberConn As ServerConnection = New ServerConnection(subscriberName)

Dim publisherConn As ServerConnection = New ServerConnection(publisherName)

' Create the objects that we need.

Dim publication As MergePublication

Dim subscription As MergePullSubscription

Try

' Connect to the Subscriber.

subscriberConn.Connect()

' Ensure that the publication exists and that

' it supports pull subscriptions.

publication = New MergePublication()

publication.Name = publicationName

publication.DatabaseName = publicationDbName

publication.ConnectionContext = publisherConn

If publication.LoadProperties() Then

If (publication.Attributes And PublicationAttributes.AllowPull) = 0 Then

publication.Attributes = publication.Attributes Or PublicationAttributes.AllowPull

End If

' Define the pull subscription.

subscription = New MergePullSubscription()

subscription.ConnectionContext = subscriberConn

subscription.PublisherName = publisherName

subscription.PublicationName = publicationName

subscription.PublicationDBName = publicationDbName

subscription.DatabaseName = subscriptionDbName

subscription.HostName = passedHostname

' Specify the Windows login credentials for the Merge Agent job.

subscription.SynchronizationAgentProcessSecurity.Login = windowsLogin

subscription.SynchronizationAgentProcessSecurity.Password = windowsPWD

' Make sure that the agent job for the subscription is created.

subscription.CreateSyncAgentByDefault = True

' Create the pull subscription at the Subscriber.

subscription.Create()

Dim registered As Boolean = False

' Verify that the subscription is not already registered.

For Each existing As MergeSubscription In _

publication.EnumSubscriptions()

If existing.SubscriberName = subscriberName Then

registered = True

End If

Next

If Not registered Then

' Register the local subscription with the Publisher.

publication.MakePullSubscriptionWellKnown(subscriberName, subscriptionDbName, SubscriptionSyncType.Automatic, MergeSubscriberType.Local, 0)

'publication.MakePullSubscriptionWellKnown(subscriberName, subscriptionDbName, SubscriptionSyncType.Automatic, MergeSubscriberType.Local, 0)

End If

Else

' Do something here if the publication does not exist.

Throw New ApplicationException(String.Format("The publication '{0}' does not exist on {1}.", publicationName, publisherName))

End If

Catch ex As Exception

' Implement the appropriate error handling here.

Throw New ApplicationException(String.Format("The subscription to {0} could not be created.", publicationName), ex)

Finally

subscriberConn.Disconnect()

publisherConn.Disconnect()

End Try

End Sub

Sub PullMergeReplication()

' Create a connection to the Subscriber.

Dim conn As ServerConnection = New ServerConnection(subscriberName)

Dim subscription As MergePullSubscription

Try

' Connect to the Subscriber.

conn.Connect()

' Define subscription properties.

subscription = New MergePullSubscription()

subscription.ConnectionContext = conn

subscription.DatabaseName = subscriptionDbName

subscription.PublisherName = publisherName

subscription.PublicationDBName = publicationDbName

subscription.PublicationName = publicationName

' If the pull subscription and the job exists, start the agent job.

If subscription.LoadProperties() And Not subscription.AgentJobId Is Nothing Then

subscription.SynchronizeWithJob()

Else

' Do something here if the subscription does not exist.

Throw New ApplicationException(String.Format("A subscription to '{0}' does not exists on {1}", publicationName, subscriberName))

End If

Catch ex As Exception

' Do appropriate error handling here.

Throw New ApplicationException("The subscription could not be synchronized.", ex)

Finally

conn.Disconnect()

End Try

End Sub

End Class

|||

this means you're trying to apply a dynamic snapshot that's not for your partition. i.e. your filter is for 'StoreA', but you're trying to apply snapshot belonging to 'StoreB'.

|||

After finding no solution to the problem, feeling that the problem has something to to with the conversion vom guid to string, I decided to have a second col in the table that was filled with a trigger: the guid converted to nvarchar.

And suddenly I knew where the problem was hiding:

hostname value: 4bb0e468-c68a-4253-ba82-f71c3a6e302d

cast( convert(varbinary,host_name()) as uniqueidentifier) -> 4BB0E468-C68A-4253-BA82-F71C3A6E302D

And that is the solution: When using a guid as the hostname and filter, the values have to be either both lower case or upper case. Otherwise you will get an empty result for dynamicly filtered tables :)

Thanks for your support

Alex

Friday, March 23, 2012

merge replication script problem

Hi all:
i set up merge replication with row and column filter in sql 2000 and
it works fine, so i generate the script and try to run this script in
another computer, i alway got errors like "table name does not exist etc",
those tables definately exist in DB.
i worked it out after i delete all column fiters in script, does any
one know what's the problem?
Cheers
nick
could you post your table schema and your publication script?
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Nick" <fsheng@.ebreathe.co.nz> wrote in message
news:euoHn5JCFHA.936@.TK2MSFTNGP12.phx.gbl...
> Hi all:
> i set up merge replication with row and column filter in sql 2000
and
> it works fine, so i generate the script and try to run this script in
> another computer, i alway got errors like "table name does not exist etc",
> those tables definately exist in DB.
> i worked it out after i delete all column fiters in script, does any
> one know what's the problem?
>
> Cheers
> nick
>

Merge replication row filter

I have a situation which I can't seem to find an answer to. I have
merge replication set up in SQL2005 and everything seems to work find
except that the row filter for a table isn't working 100%. I have 200
or so field guys who have SQL Express installed on their laptops who
syncronize data back to the server through web syncronization. The
filter in question looks like this:
SELECT <published columns> FROM [dbo].[Stores]
WHERE Division =
(SELECT DivID FROM Divisions
WHERE DistrictDivision = HOST_NAME())
The row filter works fine except when a store is moved from one
division to the next. While it shows up in the new division, it
remains in the old one. I have tested the select statements used in
the filter and they return act as expected. Has anyone seen anything
like this?
Thanks in advance
JC
Hi,
On SQL2005 there is a parameter to sp_addmergepublication called
@.allow_partition_realignment. It sounds like the option you need if
you want to remove a store from the old division. You may need to
consider realigning your current subscribers by forcing a
reinitialisation.
http://msdn2.microsoft.com/en-us/library/ms176103.aspx
Tim
On Mar 31, 6:07 pm, "JC" <jbzcoo...@.gmail.com> wrote:
> I have a situation which I can't seem to find an answer to. I have
> merge replication set up in SQL2005 and everything seems to work find
> except that the row filter for a table isn't working 100%. I have 200
> or so field guys who have SQL Express installed on their laptops who
> syncronize data back to the server through web syncronization. The
> filter in question looks like this:
> SELECT <published columns> FROM [dbo].[Stores]
> WHERE Division =
> (SELECT DivID FROM Divisions
> WHERE DistrictDivision = HOST_NAME())
> The row filter works fine except when a store is moved from one
> division to the next. While it shows up in the new division, it
> remains in the old one. I have tested the select statements used in
> the filter and they return act as expected. Has anyone seen anything
> like this?
> Thanks in advance
> JC

Monday, March 19, 2012

Merge replication not merging changes

my replication scenario involves a table that has a filter on three columns.
I update this table and the data does not get propogated to the subscriber.
effectively, I am creating "deletes" at the subscriber by invalidating the
data (i.e., updates cause it to fall outside the filter criteria)
The initial subscription works. Then I update so the data should be removed
and it doesn't happen.
I use sp_showrowreplicainfo and I can see that the generation info at the
subscriber is lower than that at the publisher.
I initiate the merge and the data does not get removed from the subscriber.
It's very late for me, so maybe I am missing something obvious.
Suggestions appreciated
regards
Steve
To answer my own question after further experimentation, it appears to depend
completely on which table you hang the join filter off.
If the parent table has its referenced row updated, the change cascades
properly down the chain.
Wow, what a tiring lesson to learn.
"SteveM" wrote:

> my replication scenario involves a table that has a filter on three columns.
> I update this table and the data does not get propogated to the subscriber.
> effectively, I am creating "deletes" at the subscriber by invalidating the
> data (i.e., updates cause it to fall outside the filter criteria)
>
|||Generation numbers are localized to the database and article. If you have
more than one subscriber the generation values for the same article on the
publisher and subscriber can vary wildly. IIRC the generation value for the
publisher in a single subscriber topology will always be one larger than the
value on the subscriber.
Check the conflict viewer to see if there is anything there.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"SteveM" <SteveM@.discussions.microsoft.com> wrote in message
news:0AC4EB4D-11DD-40C5-A1B3-7160A559B57B@.microsoft.com...
> my replication scenario involves a table that has a filter on three
> columns.
> I update this table and the data does not get propogated to the
> subscriber.
> effectively, I am creating "deletes" at the subscriber by invalidating the
> data (i.e., updates cause it to fall outside the filter criteria)
> The initial subscription works. Then I update so the data should be
> removed
> and it doesn't happen.
> I use sp_showrowreplicainfo and I can see that the generation info at the
> subscriber is lower than that at the publisher.
> I initiate the merge and the data does not get removed from the
> subscriber.
> It's very late for me, so maybe I am missing something obvious.
> Suggestions appreciated
> regards
> Steve

Monday, March 12, 2012

Merge replication join filter clause can be subquery, self join?

Hi,
I need to filter the replicated rows of a table by using a subquery that
references to itself, or by doing a self join. My filter for the table
called "aCrediAnti" looks like:
Select *
From aCrediAnti t1
Where t1.ImpSaldoAntiMonOri > 0
Or exists(select * from aCrediAnti t2
Where t2.ClaOperProvCrediAnti = t1.ClaOperCrediProv
And t2.FolOperProvCrediAnti = t1.FolOperCrediProv
And t2.ClaEmp = t1.ClaEmp
And t2.ImpSaldoAntiMonOri > 0
)
Or may be also in the self join syntax
Select *
From aCrediAnti t1
Left Join aCrediAnti t2
On t2.ClaOperProvCrediAnti = t1.ClaOperCrediProv
And t2.FolOperProvCrediAnti = t1.FolOperCrediProv
And t2.ClaEmp = t1.ClaEmp
Where t1.ImpSaldoAntiMonOri > 0
Or (
Not t2.FolOperProvCrediAnti Is Null
And t2.ImpSaldoAntiMonOri > 0
)
My problem is how to specify such a filter. For both I need to specify table
aliases (t1, t2) for using them on the join, but neither the Enterprise
Manager and sp_addmergefilter (script version) allows me to use alias. What
can I do?
Thanks in advance
Faustino Dina
If my email address starts with two 'f'
drop the first 'f' when mailing me.
I think a UDF would be ideal for something like this.
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"faustino Dina" <ffdina@.matusa.com.mx> wrote in message
news:O91w%238DkEHA.3664@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I need to filter the replicated rows of a table by using a subquery that
> references to itself, or by doing a self join. My filter for the table
> called "aCrediAnti" looks like:
> Select *
> From aCrediAnti t1
> Where t1.ImpSaldoAntiMonOri > 0
> Or exists(select * from aCrediAnti t2
> Where t2.ClaOperProvCrediAnti = t1.ClaOperCrediProv
> And t2.FolOperProvCrediAnti = t1.FolOperCrediProv
> And t2.ClaEmp = t1.ClaEmp
> And t2.ImpSaldoAntiMonOri > 0
> )
> Or may be also in the self join syntax
> Select *
> From aCrediAnti t1
> Left Join aCrediAnti t2
> On t2.ClaOperProvCrediAnti = t1.ClaOperCrediProv
> And t2.FolOperProvCrediAnti = t1.FolOperCrediProv
> And t2.ClaEmp = t1.ClaEmp
> Where t1.ImpSaldoAntiMonOri > 0
> Or (
> Not t2.FolOperProvCrediAnti Is Null
> And t2.ImpSaldoAntiMonOri > 0
> )
> My problem is how to specify such a filter. For both I need to specify
table
> aliases (t1, t2) for using them on the join, but neither the Enterprise
> Manager and sp_addmergefilter (script version) allows me to use alias.
What
> can I do?
> Thanks in advance
> --
> Faustino Dina
> If my email address starts with two 'f'
> drop the first 'f' when mailing me.
>
|||> I think a UDF would be ideal for something like this.
Thanks! Despite it took me hours to decode what "UDF" means ;-) it looks it
works
Faustino

Friday, March 9, 2012

Merge Replication Filter does not work at Subscriber

I am setting up a SQL Server Database Filter based Merge Replication between
Publisher (on Server Global) & Subscriber (on Server Site) using
EXCHANGE_TYPE '1' (Data only needs to be merged from Subscriber(Site) to
Publisher(Global) - Upload). You can consider this as a Central Subscriber
model with multiple Publications based on Filter "Siteid" push Data to
Central Subscriber Global. I have created all the Publications in the Central
Publisher Database Global (Normally central subscriber model will have
Publications on each site but I did wanted to do that due to Maintenance &
security issues )
Also I have set up conflict resolver "SQL Server Subscriber always wins the
conflict" since I want my Subscriber changes to override changes done at
Publisher.
However, I am facing this issue:
Even if I add a row at subscriber Site that is not part of Filter (it goes
into the Publisher Global). I do not want the rows other than filter clause
to replicate to Central Hub.
Any assistance is highly appreciated!
Database : SQL Server 2000 SP3a
OS: Win2003 (No Service Pack)
Vikas,
you could use an instead-of trigger for this, and divert these rows to
another table.
Alternatively you could use partitioned tables (like federated database
servers but all on one database).
Another alternative is to edit the merge triggers to not record these rows
in the metadata tables.
Rgds,
Paul Ibison
"Vikas Kohli" <VikasKohli@.discussions.microsoft.com> wrote in message
news:ACFC59F9-7CE5-4869-83D3-7CB836E6E273@.microsoft.com...
>I am setting up a SQL Server Database Filter based Merge Replication
>between
> Publisher (on Server Global) & Subscriber (on Server Site) using
> EXCHANGE_TYPE '1' (Data only needs to be merged from Subscriber(Site) to
> Publisher(Global) - Upload). You can consider this as a Central Subscriber
> model with multiple Publications based on Filter "Siteid" push Data to
> Central Subscriber Global. I have created all the Publications in the
> Central
> Publisher Database Global (Normally central subscriber model will have
> Publications on each site but I did wanted to do that due to Maintenance &
> security issues )
> Also I have set up conflict resolver "SQL Server Subscriber always wins
> the
> conflict" since I want my Subscriber changes to override changes done at
> Publisher.
> However, I am facing this issue:
> Even if I add a row at subscriber Site that is not part of Filter (it goes
> into the Publisher Global). I do not want the rows other than filter
> clause
> to replicate to Central Hub.
> Any assistance is highly appreciated!
> Database : SQL Server 2000 SP3a
> OS: Win2003 (No Service Pack)
|||Thanks Paul,
I think the 1st and 2nd options is not feasible at this moment as it
requires a lot of schema changes that will effect almost all the stored procs
in the Application.
I can only try the third option:
I would like to know which merge trigger I have to modify. Is it at the
Publisher or at the Subscriber? I am pasting below the code of Insert
trigger for Merge Replication on an Article "Accrual" for both Subscriber &
Publisher. (for eg. Filter is Siteid=1 for site 1. I do not want rows other
than Siteid 1 to be pushed from Subscriber)
Subscriber Code:
create trigger ins_FD4915FBB5824998BA19B5709C120666 on [dbo].[Accrual] for
insert as
if sessionproperty('replication_agent') = 1 and (select
trigger_nestlevel()) = 1
return
/* Declare variables */
declare @.article_rows_inserted int
select @.article_rows_inserted = count(*) from inserted
declare @.tablenick int, @.nickname int
declare @.lineage varbinary(255), @.colv1 varbinary(2048)
declare @.ccols int, @.retcode smallint, @.version int, @.curversion int,
@.oldmaxversion int
set nocount on
set @.tablenick = 6753038
select @.ccols = 20
set @.lineage = 0x0
set @.retcode = 0
select @.oldmaxversion= maxversion_at_cleanup from dbo.sysmergearticles
where nickname = @.tablenick
execute dbo.sp_MSgetreplnick @.nickname = @.nickname output
if (@.@.error <> 0)
begin
goto FAILURE
end
set @.lineage = { fn UPDATELINEAGE (0x0, @.nickname, 1) }
set @.colv1 = { fn INITCOLVS(@.ccols, @.nickname) }
if (@.@.error <> 0)
begin
goto FAILURE
end
if exists (select ts.rowguid from tsvw_FD4915FBB5824998BA19B5709C120666
ts, inserted i where ts.tablenick = @.tablenick and ts.rowguid = i.rowguidcol)
begin
select @.version = max({fn GETMAXVERSION(lineage)}) from
tsvw_FD4915FBB5824998BA19B5709C120666 where
tablenick = @.tablenick and rowguid in (select rowguidcol from inserted)
if @.version is not null
begin
-- reset lineage and colv to higher version...
set @.curversion = 0
while (@.curversion <= @.version)
begin
set @.lineage = { fn UPDATELINEAGE (@.lineage, @.nickname,
@.oldmaxversion+1) }
set @.curversion = @.curversion + 1
end
if (@.colv1 IS NOT NULL)
set @.colv1 = { fn UPDATECOLVBM(@.colv1, @.nickname, 0x01, 0x00, { fn
GETMAXVERSION(@.lineage) }) }
delete from tsvw_FD4915FBB5824998BA19B5709C120666 where tablenick =
@.tablenick and rowguid in
(select rowguidcol from inserted)
end
end
if (@.article_rows_inserted = 1)
begin
if not exists (select ct.rowguid from
ctsv_FD4915FBB5824998BA19B5709C120666 ct, inserted i where ct.tablenick =
@.tablenick and ct.rowguid = i.rowguidcol)
begin
insert into ctsv_FD4915FBB5824998BA19B5709C120666 (tablenick, rowguid,
lineage, colv1, generation, joinchangegen) select
@.tablenick, rowguidcol, @.lineage, @.colv1, A.gen_cur, A.gen_cur from
inserted,
(select top 1 nickname, gen_cur = isnull(gen_cur, 0) from
dbo.sysmergearticles where nickname = @.tablenick) as A
end
end
else
begin
insert into ctsv_FD4915FBB5824998BA19B5709C120666 (tablenick, rowguid,
lineage, colv1, generation, joinchangegen) select
@.tablenick, rowguidcol, @.lineage, @.colv1, A.gen_cur, A.gen_cur from
inserted,
(select top 1 nickname, gen_cur = isnull(gen_cur, 0) from
dbo.sysmergearticles where nickname = @.tablenick) as A
where rowguidcol not in (select rowguid from
ctsv_FD4915FBB5824998BA19B5709C120666 where tablenick = @.tablenick)
end
if @.@.error <> 0
goto FAILURE
return
FAILURE:
if @.@.trancount > 0
rollback tran
raiserror (20041, 16, -1)
return
Publisher Code
create trigger ins_FD4915FBB5824998BA19B5709C120666 on [dbo].[Accrual] for
insert as
if sessionproperty('replication_agent') = 1 and (select
trigger_nestlevel()) = 1
return
/* Declare variables */
declare @.article_rows_inserted int
select @.article_rows_inserted = count(*) from inserted
declare @.tablenick int, @.nickname int
declare @.lineage varbinary(255), @.colv1 varbinary(2048)
declare @.ccols int, @.retcode smallint, @.version int, @.curversion int,
@.oldmaxversion int
set nocount on
set @.tablenick = 6753038
select @.ccols = 20
set @.lineage = 0x0
set @.retcode = 0
select @.oldmaxversion= maxversion_at_cleanup from dbo.sysmergearticles
where nickname = @.tablenick
execute dbo.sp_MSgetreplnick @.nickname = @.nickname output
if (@.@.error <> 0)
begin
goto FAILURE
end
set @.lineage = { fn UPDATELINEAGE (0x0, @.nickname, 1) }
set @.colv1 = { fn INITCOLVS(@.ccols, @.nickname) }
if (@.@.error <> 0)
begin
goto FAILURE
end
if exists (select ts.rowguid from tsvw_FD4915FBB5824998BA19B5709C120666
ts, inserted i where ts.tablenick = @.tablenick and ts.rowguid = i.rowguidcol)
begin
select @.version = max({fn GETMAXVERSION(lineage)}) from
tsvw_FD4915FBB5824998BA19B5709C120666 where
tablenick = @.tablenick and rowguid in (select rowguidcol from inserted)
if @.version is not null
begin
-- reset lineage and colv to higher version...
set @.curversion = 0
while (@.curversion <= @.version)
begin
set @.lineage = { fn UPDATELINEAGE (@.lineage, @.nickname,
@.oldmaxversion+1) }
set @.curversion = @.curversion + 1
end
if (@.colv1 IS NOT NULL)
set @.colv1 = { fn UPDATECOLVBM(@.colv1, @.nickname, 0x01, 0x00, { fn
GETMAXVERSION(@.lineage) }) }
delete from tsvw_FD4915FBB5824998BA19B5709C120666 where tablenick =
@.tablenick and rowguid in
(select rowguidcol from inserted)
end
end
if (@.article_rows_inserted = 1)
begin
if not exists (select ct.rowguid from
ctsv_FD4915FBB5824998BA19B5709C120666 ct, inserted i where ct.tablenick =
@.tablenick and ct.rowguid = i.rowguidcol)
begin
insert into ctsv_FD4915FBB5824998BA19B5709C120666 (tablenick, rowguid,
lineage, colv1, generation, joinchangegen) select
@.tablenick, rowguidcol, @.lineage, @.colv1, A.gen_cur, A.gen_cur from
inserted,
(select top 1 nickname, gen_cur = isnull(gen_cur, 0) from
dbo.sysmergearticles where nickname = @.tablenick) as A
end
end
else
begin
insert into ctsv_FD4915FBB5824998BA19B5709C120666 (tablenick, rowguid,
lineage, colv1, generation, joinchangegen) select
@.tablenick, rowguidcol, @.lineage, @.colv1, A.gen_cur, A.gen_cur from
inserted,
(select top 1 nickname, gen_cur = isnull(gen_cur, 0) from
dbo.sysmergearticles where nickname = @.tablenick) as A
where rowguidcol not in (select rowguid from
ctsv_FD4915FBB5824998BA19B5709C120666 where tablenick = @.tablenick)
end
if @.@.error <> 0
goto FAILURE
return
FAILURE:
if @.@.trancount > 0
rollback tran
raiserror (20041, 16, -1)
return
Also kindly let me know any problem that you can foresee if I use Central
Subscriber (Globall) using Merge Replication with Ppublisher as all the sites
with Filter Siteid. I am thinking of that option also although it is very
difficult to maintain.
With Regards,
Vikas Kohli
"Paul Ibison" wrote:

> Vikas,
> you could use an instead-of trigger for this, and divert these rows to
> another table.
> Alternatively you could use partitioned tables (like federated database
> servers but all on one database).
> Another alternative is to edit the merge triggers to not record these rows
> in the metadata tables.
> Rgds,
> Paul Ibison
> "Vikas Kohli" <VikasKohli@.discussions.microsoft.com> wrote in message
> news:ACFC59F9-7CE5-4869-83D3-7CB836E6E273@.microsoft.com...
>
>
|||You'll need to edit the subscriber trigger. Don't try to understand all the
code in it - just check at the start if the 'Deleted' table refers to a row
you don't want replicated ie wrap the whole code:
if not exists (select * from deleted where ...)
begin
trigger code
end
This works for single row changes. For multiple row changes, some of which
may violate your filtering, you could try removing the rows from the deleted
table - haven't done this before but might work. If not, you'll have to use
a cursor to iterate through the deleted rows and apply the supplied trigger
code only when the row is ok to be replicated. Remember that this is Very
proprietry solution, and on reinitialization, all this code will disappear.
Rgds,
Paul Ibison
|||Hi Paul,
I have actually used the following code in all the insert & update triggers
for the article in the beginning of trigger:
if exists (select siteid from inserted where siteid=1)
Begin
--Trigger original code--
end
else
Return
For delete trigger, I have used following:
if exists (select siteid from deleted where siteid=1)
Begin
--Trigger original code--
end
else
return
Looks like this code works for even multiple inserts and multiple deletes
Appreciate if you can advise me on this now:
1. Kindly let me know if there could be any issues with the above code.
2. One issue which I can see now is following. Please let me know how to
resolve it.
Although the replication is working fine now but When I run exec
spBrowseMergeChanges 'articlename', I get all the rows listed that were
updated,deleted or inserted at the subscriber. Currently I have to do a
dummyupdate for each rowid which is not possible everytime.
3. Also kindly let me know if I coonfigure a central subscriber in Merge
Replication where the subscriber pulls the data based on Siteid filter, do
you see any issues
With regards,
Vikas Kohli
"Paul Ibison" wrote:

> You'll need to edit the subscriber trigger. Don't try to understand all the
> code in it - just check at the start if the 'Deleted' table refers to a row
> you don't want replicated ie wrap the whole code:
> if not exists (select * from deleted where ...)
> begin
> trigger code
> end
> This works for single row changes. For multiple row changes, some of which
> may violate your filtering, you could try removing the rows from the deleted
> table - haven't done this before but might work. If not, you'll have to use
> a cursor to iterate through the deleted rows and apply the supplied trigger
> code only when the row is ok to be replicated. Remember that this is Very
> proprietry solution, and on reinitialization, all this code will disappear.
> Rgds,
> Paul Ibison
>
>
|||Vikas,
the problem with this approach is that rows where the siteid <> 1 will not
end up logged and replicated. You can make sure this doesn't happen by using
a cursor or by removing the rows from the deleted table (to be tested) and
this'll avoid the need for dummy updates. Am not too sure about (3) - can
you expand a little.
Rgds,
Paul Ibison
|||Hi Paul,
Thanks for reply & Apologies for late reply as the site was lnot loading on
my Browser yesterday.
I will expalain the 3rd option:
Table A & B needs to send data from each site to the Central Hub Server. The
Data that site needs to send is based on filter Siteid.
In my current design, I have a central Publisher that pulls data from Site
using Merge Replication from each site with Filter SiteID. I have used
exchanngetype parameter 1 and Dynamic filter. This approach has only one
problem which we have discussed and could be possibly resiolved by modifying
all the replication Triggers. This option is very good from maintenance point
of view as I have look into only one server and one publication.
The second approach can be Central subscriber as Global Hub. All the sites
can act as Publishers pushing Data through merge replication to the central
Subscriber based on filter condition siteid using exchangetype 2. Appreciate
if you can let me know about this approach. The one problem for me that I can
see is that I have to maintain a lot of publications globally.
With regards,
Vikas Kohli
"Paul Ibison" wrote:

> Vikas,
> the problem with this approach is that rows where the siteid <> 1 will not
> end up logged and replicated. You can make sure this doesn't happen by using
> a cursor or by removing the rows from the deleted table (to be tested) and
> this'll avoid the need for dummy updates. Am not too sure about (3) - can
> you expand a little.
> Rgds,
> Paul Ibison
>
>

Wednesday, March 7, 2012

Merge Replication Error

In Merge Replication, I am not able to replicate one table having more than 5 GB data to the subscriber. If I have filter on the table I am able to do. I couldn't understand the problem? Any one having any idea on the same?

For your information.

I have 1.7GB free space in C drive. Is it a space problem in C drive? Actually my data base is storing in E drive. It has 30GB free space. But Sql Server installed in D drive it has 2 GB free space.

Thanks in advance

Kasi.

What is the error youre getting? Are you getting failure generating snapshot, or are you getting failure when applying the snapshot to the subscriber?

|||

Error Message:

Replication-Replication Merge Subsystem: agent TRPSQL3-ThomsonResearch-TR PUb-TRPSQL2-7 failed. The merge process was unable to deliver the snapshot to the Subscriber. If using Web synchronization, the merge process may have been unable to create or write to the message file. When troubleshooting, restart the synchronization with verbose history log

I have got the above error message

|||it's possible the merge agent is timing out before the jobis completed, you can try increasing the QUeryTImeout paramter value for the agent to something larger, like 600 or 900. 5 GB is a lot of data.

Merge Replication Error

In Merge Replication, I am not able to replicate one table having more than 5 GB data to the subscriber. If I have filter on the table I am able to do. I couldn't understand the problem? Any one having any idea on the same?

For your information.

I have 1.7GB free space in C drive. Is it a space problem in C drive? Actually my data base is storing in E drive. It has 30GB free space. But Sql Server installed in D drive it has 2 GB free space.

Thanks in advance

Kasi.

What is the error youre getting? Are you getting failure generating snapshot, or are you getting failure when applying the snapshot to the subscriber?

|||

Error Message:

Replication-Replication Merge Subsystem: agent TRPSQL3-ThomsonResearch-TR PUb-TRPSQL2-7 failed. The merge process was unable to deliver the snapshot to the Subscriber. If using Web synchronization, the merge process may have been unable to create or write to the message file. When troubleshooting, restart the synchronization with verbose history log

I have got the above error message

|||it's possible the merge agent is timing out before the jobis completed, you can try increasing the QUeryTImeout paramter value for the agent to something larger, like 600 or 900. 5 GB is a lot of data.

Saturday, February 25, 2012

Merge Replication Conditional Filter with UDF Problem

I'm performing Merge Replication between SQL Server 2000/SQL CE using Dynamic Filters.
I would like a conditional filter based on the Host_Name(). I've written and tested a UDF
in Query Analyzer called SELECT_Stores_RepID. In the Dynamic Filters properties for the
Stores Table I've tried many different things such as:
SELECT <published_columns> FROM [dbo].[Stores] WHERE dbo.SELECT_Stores_RepID (HOST_NAME())
All them give me errors. My question is what is the correct syntax to use my UDF? The documentation
on this is very poor.
Cheers
it should be something like this
select <punished_columns> from <<Table>> where au_id in (select au_id from dbo.Authors_filter('CA'))
There may be more efficient ways of doing this.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
|||Hi Hilary,
Thanks for the help. I tried to apply it to my Dynamic Filter...
SELECT <published_columns> FROM [dbo].[Stores] WHERE
Stores.StoreID IN (SELECT StoreID FROM dbo.SELECT_Stores_RepID(HOST_NAME())
but I'm receiving the following error...
Incorrect Syntax near '('
Once again, I can't see where the problem is with this statment ?
|||Sorry typo in my post ...
(SELECT StoreID FROM dbo.SELECT_Stores_RepID(HOST_NAME())
Should be (extra bracket)...
(SELECT StoreID FROM dbo.SELECT_Stores_RepID(HOST_NAME()))
Still getting the same problem as before.
-- Cube wrote: --
Hi Hilary,
Thanks for the help. I tried to apply it to my Dynamic Filter...
SELECT <published_columns> FROM [dbo].[Stores] WHERE
Stores.StoreID IN (SELECT StoreID FROM dbo.SELECT_Stores_RepID(HOST_NAME())
but I'm receiving the following error...
Incorrect Syntax near '('
Once again, I can't see where the problem is with this statment ?
|||can you post your UDF.
BTW - I should warn you that UDF's don't always offer the best performance. Also Host_Name() is evaluated where the merge agent is run. If you kick it off on EM runing it on your desktop it will evaluated to your machine name.
If you kick if off on the subscriber as a pull subscription it will resolve correctly.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
|||I'm still getting this error in Replication. Does anyone know if its a known issue?
The error is that when I call my UDF below in my Dynamic Filter and pass in
HOST_NAME() I get an incorrect syntax near '(' error.
Ciaran
-- Cube wrote: --
Hi Hilary,
Please find below my UDF. The RepID in my table is an int, which I CAST so I can
compare it to my Host_Name(). I'm interested to know your opinion. Also, if UDF's
don't offer best performance, do I have other options apart from creating a seperate
publication?
ALTER FUNCTION dbo.SELECT_Stores_RepID
(
@.inRepIDchar(4)
)
RETURNS @.Stores TABLE (StoreID int)
AS
BEGIN
IF (@.inRepID = '8')
INSERT INTO @.Stores
SELECTStoreID FROM Stores
ELSE
INSERT INTO @.Stores
SELECTStoreID
FROM Stores
WHERE CAST(Stores.RepID AS char(4)) = @.inRepID
RETURN
END
BTW - Some history behind all this. I have some HandHeld Devices deployed with my custom app.
The Replication depends on the RepID, which is set through the Host_Name() on the device, pulling
back the users specified data. Now, there is a requirement to pull back all data in some cases
e.g. management, without modifying the software on the client. Henece, the reasons for the
IF RepID = X conditional filter.

Monday, February 20, 2012

Merge Replication and Filtering by date

With SQL Server 2005 adding a merge filter that used a column with a date did not work very well. I have a table that has an expiration date. Ideally, I would want to set a filter that says send to the subscriber if getdate() < expirationdate. The problem in 2005 is that since the data in the row does not change, the row will not be deleted from the subscription when the date passes the expiration date. Microsoft has recommended that another column called something like IsActive should be added and updated every day. This is sometimes not possible. Has this issue been addressed in SQL Server 2008?

Merge replication is trigger-based, you have to explicitly make a change for merge replication to track it, this has always been the design, we use the metadata tables to determine what changes need to be uploaded/downloaded. The recommendation for an "IsExpired" column is a common and easy workaround, you can create a job that runs daily/weekly/hourly to update this column based on the expiration date.

Can you explain in more detail why this workaround is not possible for you? Maybe we can offer another solution/workaround.

|||

I don't really have a particular problem in mind. I was just wondering if SQL 2008 has changed in such a way that the workaround is not needed any longer. If it isn't, then I can just continue to do what I have been, but if it has changed I just wanted to be aware of it. Thanks for your help.

Merge Replication and Dynamic Filters

Hi.
I am developing an Windows Mobile 5.0 Application for the MotoQ. It
uses merge replication and everything works fine. The DB has a
dynamic filter on it so that it only sends the data that matches the
SUSER_SNAME(). The problem arises when a user, other than the inital
user for the program, wants to login using that device.
I want to have it drop the old subscription and start a new one with
the new user. I have coded it exactly as I want it, the thing is, it
still sends data for the first user. The only way for me to use the
program with a new, different, user is to reinstall it. I highly
doubt this is the only solution...
Any ideas are greatly welcome.
Thanks,
SmP
I wish I could help you, but I am having the same trouble. I would love to
see an answer.
"smp9737@.gmail.com" wrote:

> Hi.
> I am developing an Windows Mobile 5.0 Application for the MotoQ. It
> uses merge replication and everything works fine. The DB has a
> dynamic filter on it so that it only sends the data that matches the
> SUSER_SNAME(). The problem arises when a user, other than the inital
> user for the program, wants to login using that device.
> I want to have it drop the old subscription and start a new one with
> the new user. I have coded it exactly as I want it, the thing is, it
> still sends data for the first user. The only way for me to use the
> program with a new, different, user is to reinstall it. I highly
> doubt this is the only solution...
>
> Any ideas are greatly welcome.
> Thanks,
> SmP
>

Merge Replication and Deletes

Hi there,
I have four databases set up with merge replication. I have a filter that
says only replicate a record if its timestamp is greater than one day ago (I
don't care about any data older than one day).
If I now go into Database #1 and delete a record that is older than one day,
I do not expect to see this record deleted from the other databases (in
other words, I expect that it would remain in the others). However, all the
deletes for records older than one day ARE being replicated to the other
databases. I'd really prefer that this didn't happen.
Does anyone know why this occurs?
Thanks,
Kevin
Because you told it to. You said that your filter says to only replicate if
the timestamp is greater than one day ago, and it's timestamp is greater than
1 day ago.
If you want it to not be replicated, then update the timestamp to the
current date first and then delete.
Robert.
"Kevin Thomas" wrote:

> Hi there,
> I have four databases set up with merge replication. I have a filter that
> says only replicate a record if its timestamp is greater than one day ago (I
> don't care about any data older than one day).
> If I now go into Database #1 and delete a record that is older than one day,
> I do not expect to see this record deleted from the other databases (in
> other words, I expect that it would remain in the others). However, all the
> deletes for records older than one day ARE being replicated to the other
> databases. I'd really prefer that this didn't happen.
> Does anyone know why this occurs?
> Thanks,
> Kevin
>
>
|||Perhaps I misspoke, I apologize. I only want to replicate data that is less
than a day old. I want to delete data that is greater than a day old. When
I delete the data that is older than one day, those deletes are replicated,
even though I don't expect that they would because of the filter.
Thanks for your help,
Kevin
"Robert Davis" <RobertDavis@.discussions.microsoft.com> wrote in message
news:E1D36A03-CF46-4EAB-BE05-31D048FDC59B@.microsoft.com...[vbcol=seagreen]
> Because you told it to. You said that your filter says to only replicate
> if
> the timestamp is greater than one day ago, and it's timestamp is greater
> than
> 1 day ago.
> If you want it to not be replicated, then update the timestamp to the
> current date first and then delete.
> Robert.
> "Kevin Thomas" wrote: