Hello all,
I'm having trouble with my Merge Replication setup in regards to changing the HostName property of the SqlCeReplication object. As we all know, if you modify the HostName value, you must then call the ReinitializeSubscription(true) method before calling Synchronize(). Unfortunately, this isn't working for me. Following this sequence of steps consistently results in error messages saying that I need to either call ReinitializeSubscription, or change my HostName back to it's original value. Has anyone ever experienced this problem?
Regards,
Rob Tiffany
Hey Rob,
You are correct, once you specify a HostName value for a subscriber, if you want to change that value later, you must call SqlCeReplication.ReinitializeSubscription(True) followed by .Synchronize() to effectively make the change.
I built an app recently for a large field service scenario where the mobile device can change hands from field worker to field worker. I decided to use the field worker's unique identifier as the value for HostName so that I could replicate only the appropriate data for a given worker to a given SQL Mobile database. If the device changes hands, here is the process of making the change to HostName and reinitializing:
Public Function Synchronize() As Boolean
Dim retVal As Boolean = False
Dim repl As SqlCeReplication = GetReplication()
If repl Is Nothing Then
Return False
End If
Try
If Globals.GetInstance().HostNameChanged Then
repl.ReinitializeSubscription(True)
Globals.GetInstance().HostNameChanged = False
End If
repl.Synchronize()
etc etc etc
If you are doing something similar and getting an error, could you post the details on the error itself and Laxmi and I can look into it? Also, some info on your configuration (assume you are talking about SQL Mobile and SS2005?)
Regards,
Darren
|||Yeah, that's what I'm doing too. My Sync code blocks looks like the following:
private void replicate(bool reInit)
{
SqlCeReplication repl = new SqlCeReplication();
repl.InternetUrl = Settings1.Default.InternetURL;
repl.InternetLogin = Settings1.Default.InternetLogin;
repl.InternetPassword = Settings1.Default.InternetPassword;
repl.Publisher = Settings1.Default.Publisher;
repl.PublisherDatabase = Settings1.Default.PublisherDatabase;
repl.Publication = Settings1.Default.Publication;
repl.PublisherSecurityMode = SecurityType.NTAuthentication;
repl.SubscriberConnectionString = @."Data Source=" + localFolder + "MyDB.sdf;Password=p@.ssw0rd;";
repl.Subscriber = Settings1.Default.Subscriber;
repl.HostName = txtAgentId.Text;
repl.CompressionLevel = Settings1.Default.CompressionLevel;
repl.ExchangeType = ExchangeType.BiDirectional;
try
{
if (!File.Exists(localFolder + "MyDB.sdf"))
{
repl.AddSubscription(AddOption.CreateDatabase);
}
if (reInit == true)
{
repl.ReinitializeSubscription(true);
}
// Synchronize with SQL Server 2005
repl.Synchronize();
}
finally
{
repl.Dispose();
}
}
If the user changes the HostName, then I pass "true" to the method above to call ReinitializeSubscription(true).
Thanks,
Rob
|||there is a possible code path in your code where the database does not exist and you (are going to create it using AddOption.CreateDatabase on the first replication), but reinit can also be true - this won't work - you cannot mix CreateDatabase and Reinit in the same call to Synchronize.
Could that be what's happening? What error messages are you getting?
Darren
|||I don't have the exact error message in front of me now, but is says something like:
Error: Changing the HostName requires a call to ReinitializeSubscription() or change your HostName back to the original value. HostName = 2, Original HostName = 1.
Something like that. Keep in mind that it will even throw this same error when I call ReinitializeSubscription().
To answer your other question, I haven't experienced the possible code path error you described where the database doesn't exist. It should also be known that this is a desktop XP project and not on Windows Mobile. Just in case we have subtle differences or issues between the desktop and handheld dlls. I'm trying to do some load testing and the desktop is the only way to create enough clients.
Rob
No comments:
Post a Comment