How to mimic replmerg.exe in vb.net

Hello,

On an existing Merge Pull Subscription (Subscriber: SQL Express) via websync how can we start replication via vb.net We can use the cmd line replmerge.exe and all works fine however we would like this to be cleaner as it's going to be on demand sync. I saw in BOL about the RMO and how to create pubs/subs but nothing telling me how to actually start the replication process. Is there a sample of how to start the replication process in vb.net for websync Thanks in advance.

John



Answer this question

How to mimic replmerg.exe in vb.net

  • Stewart_Whaley

    Mahesh,

    Here is the command line.

    "C:\Program Files\Microsoft SQL Server\90\COM\REPLMERG.EXE" -Publisher b-db\bdbserver -Publication pub_arizona -Subscriber hh3-01\hh3_01 -Distributor b-db\bdbserver -PublisherDB arizona -SubscriberDB arizona -PublisherSecurityMode 1 -Output -SubscriberSecurityMode 1  -SubscriptionType 1 -DistributorSecurityMode 1 -InternetURL https://replia.domain.com/replia -InternetLogin domain\user -InternetPassword PAssWoRD

    As a test I took the exact same source code and applied it on another box and it works. The difference is one box is XP Pro, with VS 2005 installed the other box is just a w2k (this is a box which mimics clients settings). Should this be compatible on the w2k box w2k box is the one having the issue saying it cannot connect to the distributor. The cmd line replmerg works on both XP Pro and w2k.


  • Davidsfg

    just a side note regarding the win2k and winxp issue you have - you're connecting using -PublisherSecurityMode 1.  Does the login account on your winxp machine have access to the distributor machine
  • Sandeep Singh Kushwah

    Guys,

    Thanks for the postings so far. The names I just changed cause my boss is a security freak. So I did some find and replaces so that isn't the issue. I guess the XP works cause it's part of the domain so it's some security setting. What should the security setting be for a user not belonging to the domain. Below are the two pieces of code that work. The replmerge.exe works on both the XP Pro, belonging to the domain, and the w2k which doesn't belong to the domain.

     

    John

     

    replmerge.exe

    "C:\Program Files\Microsoft SQL Server\90\COM\REPLMERG.EXE" -Publisher computer\bdbserver -Publication pub_arizona -Subscriber hh3-01\hh3_01 -Distributor computer\bdbserver -PublisherDB arizona -SubscriberDB arizona -PublisherSecurityMode 1 -Output -SubscriberSecurityMode 1  -SubscriptionType 1 -DistributorSecurityMode 1 -InternetURL https://www.domain.com/replia -InternetLogin domain\user -InternetPassword password

    vb.net code

    ' Define the server, publication, and database names.
            Dim publisherInstance As String = "computer\bdbserver"
            Dim subscriberName As String = "hh3-01\hh3_01"
            Dim publisherName As String = publisherInstance
            Dim publicationName As String = "pub_arizona"
            Dim subscriptionDbName As String = "arizona"
            Dim publicationDbName As String = "arizona"
            Dim hostname As String = Nothing
            Dim webSyncUrl As String = "https://www.domain.com/replia/replisapi.dll"
            Dim winLogin As String = "domain\user"
            Dim winPassword As String = "password"
            ' Create a connection to the Subscriber.
            Dim conn As ServerConnection = New ServerConnection(subscriberName)

            Dim subscription As MergePullSubscription
            Dim agent As MergeSynchronizationAgent

            Try
                ' Connect to the Subscriber.
                conn.Connect()

                ' Define the pull subscription.
                subscription = New MergePullSubscription()
                subscription.ConnectionContext = conn
                subscription.DatabaseName = subscriptionDbName
                subscription.PublisherName = publisherName
                subscription.PublicationDBName = publicationDbName
                subscription.PublicationName = publicationName

                ' If the pull subscription exists, then start the synchronization.
                If subscription.LoadProperties() Then
                    ' Get the agent for the subscription.
                    agent = subscription.SynchronizationAgent

                    ' Check that we have enough metadata to start the agent.
                    If agent.PublisherSecurityMode = Nothing Then
                        ' Set the required properties that could not be returned
                        ' from the MSsubscription_properties table.
                        agent.PublisherSecurityMode = SecurityMode.Integrated
                        agent.Distributor = publisherInstance
                        agent.DistributorSecurityMode = SecurityMode.Integrated
                        agent.HostName = hostname

                        ' Set optional Web synchronization properties.
                        agent.UseWebSynchronization = True
                        agent.InternetUrl = webSyncUrl
                        agent.InternetSecurityMode = SecurityMode.Standard
                        agent.InternetLogin = winLogin
                        agent.InternetPassword = winPassword
                    End If

                    ' Enable agent logging to the console.
                    agent.OutputVerboseLevel = 2
                    If File.Exists(c:\output.txt) Then
                        Kill(c:\output.txt)
                    End If
                    agent.Output = c:\output.txt

                    ' Synchronously start the Merge Agent for the subscription.
                    agent.Synchronize()
                Else
                    ' Do something here if the pull subscription does not exist.
                    Throw New ApplicationException(String.Format( _
                     "A subscription to '{0}' does not exist on {1}", _
                     publicationName, subscriberName))
                End If
            Catch ex As Exception
                ' Implement appropriate error handling here.
                Throw New ApplicationException("The subscription could not be " + _
                 "synchronized. Verify that the subscription has " + _
                 "been defined correctly.", ex)
            Finally
                conn.Disconnect()
            End Try


  • Jay Turner

    does replmerg.exe runs fine with or without web sync   Is your IIS server enabled properly

    Here's more information on how to configure your server for web synchronization.

    http://msdn2.microsoft.com/en-us/library/ms151763.aspx

     


  • raymillr

    I believe the command line you posted is not the same as the one you run with the vb code above, because the server names are totally different.

    Can you try SQL authentication

    Also from command line, can you run a query connecting to the distributor from the machine you are having trouble

    There should be no difference between Win2K and XP in running the code and especially when connecting to the distributor.



  • anthon

    Greg,

      We can run replmerg.exe using websync perfectly fine. So I am assuming that IIS is configured correctly, unless we have to specifically make a change so that a vb.net app can start the replication process.


  • npt

    How about using SQL authentication (-PublisherSecurityMode 0 -PublisherLogin <Someuser> -PublisherPassword <SomePassword> -DistributorSecurityMode 0 -DistributorLogin <Someuser> -DistributorPassword <SomePassword>)

  • McGeas

    sorry, i should have said -DistributorSecurityMode 1.
  • kristoff1313

    Mahesh, I'll give it a try first thing in the morning. Thanks so far. John
  • Emmanuel Huna

    Mahesh, are you wanting me to try this using replmerge.exe that currently works. i am having the problem with the vb.net code
  • ThafrknJOA

    Mahesh,

       I found that on the BOL. I am trying to work with that code snippet but I get errors trying to connect to the distributor. Any ideas Running replmerg works fine.

    Variables

    Dim subscriberName As String = 'Subscriber-01\Subscriber_01'

    Dim publisherName As String = "serverdb\bdbserver"

    Dim publicationName As String = "pub_arizona"

    Dim subscriptionDbName As String = "arizona"

    Dim publicationDbName As String = "arizona"

    Dim InternetLogin As String = "domain\user"

    Dim InternetPassword As String = "password"

    Dim hostname As String = ""

    Dim webSyncUrl As String = https://www.domain.net/replia/replisapi.dll

    error log:

    2005-12-20 21:18:41.817 Connecting to OLE DB Subscriber at datasource: 'Subscriber-01\Subscriber_01', location: '', catalog: 'arizona', providerstring: '' using provider 'SQLNCLI'
    2005-12-20 21:18:41.988 OLE DB Subscriber: Subscriber-01\Subscriber_01
       DBMS: Microsoft SQL Server
       Version: 09.00.1399
       catalog name: arizona
       user name: dbo
       API conformance: 0
       SQL conformance: 0
       transaction capable: 1
       read only: F
       identifier quote char: "
       non_nullable_columns: 0
       owner usage: 15
       max table name len: 128
       max column name len: 128
       need long data len:
       max columns in table: 1000
       max columns in index: 16
       max char literal len: 131072
       max statement len: 131072
       max row size: 131072
    2005-12-20 21:18:42.048 OLE DB Subscriber 'Subscriber-01\Subscriber_01': {call sp_MSgetversion }
    2005-12-20 21:18:42.108 OLE DB Subscriber 'Subscriber-01\Subscriber_01': set nocount on declare @dbname sysname select @dbname = db_name() declare @collation nvarchar(255) select @collation = convert(nvarchar(255), databasepropertyex(@dbname, N'COLLATION')) select collationproperty(@collation, N'CODEPAGE') as 'CodePage', collationproperty(@collation, N'LCID') as 'LCID', collationproperty(@collation, N'COMPARISONSTYLE') as 'ComparisonStyle',cast(case when convert (int,databasepropertyex (@dbname,'comparisonstyle')) & 0x1 = 0x1 then 0 else 1 end as bit) as DB_CaseSensitive,cast(case when convert (int,serverproperty ('comparisonstyle')) & 0x1 = 0x1 then 0 else 1 end as bit) as Server_CaseSensitive set nocount off
    2005-12-20 21:18:42.148 OLE DB Subscriber 'Subscriber-01\Subscriber_01': { =call sp_helpsubscription_properties (N'serverdb\bdbserver', N'arizona', N'pub_arizona')}
    2005-12-20 21:18:42.168 Distributor security mode: 1, login name: , password: ********.
    2005-12-20 21:18:42.198 Connecting to OLE DB Distributor at datasource: 'serverdb\bdbserver', location: '', catalog: '', providerstring: '' using provider 'SQLNCLI'
    2005-12-20 21:18:42.278 The process could not connect to Distributor 'serverdb\bdbserver'.
    2005-12-20 21:18:42.288 OLE DB Subscriber 'Subscriber-01\Subscriber_01': {call sys.sp_MSadd_merge_history90 ( , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , )}
    2005-12-20 21:18:42.398 The process could not connect to Distributor 'serverdb\bdbserver'.
    2005-12-20 21:18:42.458 Disconnecting from OLE DB Subscriber 'Subscriber-01\Subscriber_01'
    2005-12-20 21:18:42.458 Disconnecting from OLE DB Subscriber 'Subscriber-01\Subscriber_01'
    2005-12-20 21:18:42.468 Disconnecting from OLE DB Distributor 'serverdb\bdbserver'
    2005-12-20 21:18:42.478 Disconnecting from OLE DB Distributor 'serverdb\bdbserver'

     

     


  • Don Brinn

    See if these code examples help which are listed in:

    http://msdn2.microsoft.com/en-us/library/ms147890.aspx



  • Wrongun

    Can you try with SQL authentication when connecting to the Distributor

    I assume your Distributor and Publisher are the same

    What credential are you using to run the sync Does that user have access to the Publisher and Distributor

    Can you post the merge command line that worked without errors



  • derekp

    I meant using VB code, do SQL authentication for the Publisher/Distributor connection

  • How to mimic replmerg.exe in vb.net