Hi Jeremy,
Based on your VB.NET code and the C# code in the article, I first wrote a
test C# application (since I have little experience of VB.NET), however I
could not synchronize it successfully. Based on my further research,
compared the settings with the settings in the subscription's Properties
window in SSMS, finally I found that the problem was caused by the fact
that I did not specify the publisher connection information and distributor
connection information. After I explicitly specify them, the
synchronization worked perfectly. The code is as following:
private void button1_Click(object sender, EventArgs e)
{
// Define the server, publication, and database names.
string subscriberName = "155952M4";
string publisherName = "155952M2";
string distributorName = "155952M3";
string publicationName = "MyReplPub";
string subscriptionDbName = "MySub";
string publicationDbName = "MyPub";
string hostname = @"155952M4";
string webSyncUrl = "https://" + distributorName +
"/Mywebsync/replisapi.dll";
// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);
MergePullSubscription subscription;
MergeSynchronizationAgent agent;
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())
{
// Get the agent for the subscription.
agent = subscription.SynchronizationAgent;
agent.PublisherSecurityMode = SecurityMode.Standard;
agent.PublisherLogin = "sa";
agent.PublisherPassword = "P@ssw0rd";
agent.DistributorSecurityMode = SecurityMode.Standard;
agent.DistributorLogin = "sa";
agent.DistributorPassword = " P@ssw0rd ";
agent.OutputVerboseLevel = 1;
agent.Output = "";
// 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));
}
}
catch (Exception ex)
{
// 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();
}
}
I removed those code lines within the scope of "if
(agent.PublisherSecurityMode == null)" because they never have opportunity
to be executed.
I configured my subscription on the subscriber in SSMS. Some important
settings are as following:
" Agent process account: 155952M4\Administrator (This is a local account
since it is not in my domain)
" Distributor connection and Publisher connection use "sa" as the login
account;
" Web server address:
https://155952m3.chang.com/mywebsync/replisapi.dll
" Web server connection: Basic Authentication
----User name: Administrator
----Password: P@ssw0rd
One important thing you need to pay attention to is the connection settings
in Internet Explorer since they may impact the underlying API's behavior.
On your subscriber, open your IE, click Tools->Internet Options, switch to
the Connections tab, click LAN settings and check the following:
1. Ensure that "Automatically detect settings" is NOT checked.
2. If you use a Proxy server, ensure that you select "Bypass proxy server
for local addresses" and that your proxy server can parse the URL which is
used for web synchronization. Take my test for example, if the proxy can
recognize 155952M3, however cannot parse 155952m3.chang.com, it will not
work and you will need to contact your network administrator to handle
this.
Hope this helps. If you have any other questions or concerns, please feel
free to let me know.
Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg RemoveThis @microsoft.com.
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
>> Stay informed about: Merge replication: The process could not read file ... due..