0
Answer

Unable to connect to replication subscriber when using Web Sync Services

Bob Shaw

Bob Shaw

16y
2.8k
1
We are working on a SQL Server 2005 Replication project that has to use custom business logic to handle which records are to get merged to the publisher.

When a new record is sent from the Publisher to the subscriber it's able to make the connection to the subscriber in the Initialize() function so the handlers can verify that the record is valid for insertion.

When the Subscriber goes to upload a new record to the publisher it's not able to make a connection to the subscriber in the Initialize() function. We get the default error that SQL 2005 gives if it cant make a connection. I have the code we are testing with below.

Has anyone ran into this type of problem before? or are we going about this in the wrong way. Our goal is to allow what we called Completed Accounts to get published to the subscribers through the SQL Filters and the same thing goes for accounts coming from the subscribers. We only want completed accounts from them and any incomplete accounts should stay with that subscribers until its marked complete. We tried using just the filters on the publisher but it would delete all the incomplete accounts on the subscriber when a replication was executed.

// Implement the Initialize method to get publication
// and subscription information.
public override void Initialize(
        
string publisher,
        string subscriber,
        string distributor,
        string publisherDB,
        string subscriberDB,
        string articleName)
{
        SqlConnectionStringBuilder pubString = new SqlConnectionStringBuilder();
        pubString.InitialCatalog = publisherDB;
        pubString.DataSource = publisher;
        pubString.IntegratedSecurity = false;
        pubString.UserID = "UserID";
        pubString.Password = "Password";

        // Create a connection to the Publisher.
        connectionPub = new SqlConnection(pubString.ToString());
        try
        {
                // Open the connection to the Publisher.
                connectionPub.Open();
        }
        catch (Exception ex)
        {
                //Custom error log function
                Write_Log("Publisher Initialize Error: " + ex.Message + " Client " + connectionPub.ConnectionString);
        }

        SqlConnectionStringBuilder subsString = new SqlConnectionStringBuilder();
        subsString.InitialCatalog = subscriberDB;
        subsString.DataSource = subscriber;
        subsString.IntegratedSecurity = false;
        subsString.UserID = "UserID";
        subsString.Password = "Password";

        // Create a connection to the Subscriber.
        connectionSubs = new SqlConnection(subsString.ToString());
        try
        {
                // Open the connection to the Subscriber.
                connectionSubs.Open();
        }
        catch (Exception ex)
        {
                //Custom error log function
                Write_Log("Subscriber Initialize Error: " + ex.Message + " Client " + connectionSubs.ConnectionString);
        }
}