Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 SQL-Server
I am trying to create a Merge Replication using RMO Programming which i got from here

string publisherName = "DataSourceName";
        string publicationName = "AdvWorksSalesOrdersMerge";
        string publicationDbName = "AdventureWorksDW2008R2";
        ReplicationDatabase publicationDb;
        MergePublication publication;
        // Create a connection to the Publisher.
        ServerConnection conn = new ServerConnection(publisherName);
          try
        {
             //Connect to the Publisher.
            conn.Connect();
 
            // Enable the database for merge publication.               
            publicationDb = new ReplicationDatabase(publicationDbName, conn);
            if (publicationDb.LoadProperties())
            {
                if (!publicationDb.EnabledMergePublishing)
                {
                    publicationDb.EnabledMergePublishing = true;
                }
            }
            else
            {
               //  Do something here if the database does not exist. 
                throw new ApplicationException(String.Format(
                    "The {0} database does not exist on {1}.",
                    publicationDb, publisherName));
            }
 
            // Set the required properties for the merge publication.
            publication = new MergePublication();
            publication.ConnectionContext = conn;
            publication.Name = publicationName;
            publication.DatabaseName = publicationDbName;
 
            // Enable precomputed partitions.
            publication.PartitionGroupsOption = PartitionGroupsOption.True;
 
             //Specify the Windows account under which the Snapshot Agent job runs.
            // This account will be used for the local connection to the 
            // Distributor and all agent connections that use Windows Authentication.

              publication.SnapshotGenerationAgentProcessSecurity.Login = userid;
               publication.SnapshotGenerationAgentProcessSecurity.Password = password;
 
             //Explicitly set the security mode for the Publisher connection
            // Windows Authentication (the default).
            publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = true;
 
             //Enable Subscribers to request snapshot generation and filtering.
            publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;
            publication.Attributes |= PublicationAttributes.DynamicFilters;
 
            // Enable pull and push subscriptions.
            publication.Attributes |= PublicationAttributes.AllowPull;
            publication.Attributes |= PublicationAttributes.AllowPush;
 
            if (!publication.IsExistingObject)
            {
                 //Create the merge publication.
                publication.Create();
 
                // Create a Snapshot Agent job for the publication.
                publication.CreateSnapshotAgent();
            }
            else
            {
                throw new ApplicationException(String.Format(
                    "The {0} publication already exists.", publicationName));
            }
 
        }
 
        catch (Exception ex)
        {
             //Implement custom application error handling here.
            throw new Exception(String.Format("The publication {0} could not be created.", publicationName), ex);
 
        }
        finally
        {
            conn.Disconnect();
        }


but at this line
 
publicationDb.EnabledTransPublishing = true;
 
i am getting error -" An exception occurred while executing a Transact-SQL statement or batch."
 
So please help me out from this problem ..
 
waiting for your answers..

Posted 3-Aug-12 1:16am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Did you specify the correct userid-password for the connection? Security privilege in place?
 
Have a look at this MSDN support thread[^], not exactly same but hints on system-administrator account in place and active.
  Permalink  
Comments
Sourav Kumar Panda at 7-Aug-12 10:47am
   
Yes all credentials are correct and Connection is also established but at the next line i.e. (publicationDb.EnabledTransPublishing = true;) i m getting error.
 
The control not even going this line also
 
publication.SnapshotGenerationAgentProcessSecurity.Login = userid;
publication.SnapshotGenerationAgentProcessSecurity.Password = password;
 
thnx for your replay..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 310
1 OriginalGriff 295
2 Afzaal Ahmad Zeeshan 224
3 Sergey Alexandrovich Kryukov 195
4 BillWoodruff 160
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 3 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100