Wednesday, March 7, 2012

Exception in EnumMergeDynamicSnapshotJobs

Hi,

I'm manually creating dynamic snapshots for a push merge subscription, however I often get an exception thrown when I call EnumMergeDynamicSnapshotJobs. The exception says:

Unable to cast object of type 'System.Byte' to type 'System.String'.

The stack trace is:

at System.Data.SqlClient.SqlBuffer.get_String()

at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)

at Microsoft.SqlServer.Replication.ReplicationObject.SafeGetString(SqlDataReader lclReader, Int32 nColumn, Int32 nLength)

at Microsoft.SqlServer.Replication.MergePublication.EnumMergeDynamicSnapshotJobs()

at ART.AlphaRMS.DatabaseManagementLibrary.SMOCommands.CreateDynamicSnapshot(MergePublication publication, MergeSubscription subscription, String dynamicSnapshotLocation) in ...

Has anyone seen this exception here before?

Thanks for your help

Graham

Can you post how you are creating the dynamic snapshots.

Using the UI to create a partition and the job and then enumerating the job using EnumMergeDynamicSnapshotJobs() does not show me any problems. Please post your code snippet.

|||

Hi Mahesh, I create the snapshot in code (RMO). I do not see this error every time though, it is one of those intermitant problems!

public string CreateDynamicSnapshot(MergePublication publication, MergeSubscription subscription, string dynamicSnapshotLocation)

{

string snapshotLocation = string.Empty;

try

{

// Pre-generate the dynamic snapshot as it may be that we

// want to ship it off to a remote server.

if (!string.IsNullOrEmpty(dynamicSnapshotLocation))

{

string publicationName = publication.Name;

string publicationDbName = publication.DatabaseName;

string publisherName = publication.SqlServerName;

string distributorName = publication.SqlServerName;

// Set a weekly schedule for the filtered data snapshot.

ReplicationAgentSchedule schedule = new ReplicationAgentSchedule();

schedule.FrequencyType = ScheduleFrequencyType.Weekly;

schedule.FrequencyRecurrenceFactor = 1;

schedule.FrequencyInterval = Convert.ToInt32(0x001);

// Set the value of Hostname that defines the data partition.

MergePartition partition = new MergePartition();

partition.DynamicFilterHostName = subscription.HostName;

MergeDynamicSnapshotJob snapshotAgentJob = new MergeDynamicSnapshotJob();

snapshotAgentJob.DynamicFilterHostName = subscription.HostName;

// Before creating the new job, make sure any old instances are deleted.

foreach (MergeDynamicSnapshotJob agentJob in publication.EnumMergeDynamicSnapshotJobs())

{

if (string.Compare(agentJob.DynamicFilterHostName, snapshotAgentJob.DynamicFilterHostName, true) == 0)

{

logger.Debug("Found existing dynamic snapshot job, deleting it.");

publication.RemoveMergeDynamicSnapshotJob(agentJob.Name);

}

}

logger.Debug("Creating new dynamic snapshot job for partition " + partition.DynamicFilterHostName);

// Create the partition for the publication with the defined schedule.

publication.AddMergePartition(partition);

publication.AddMergeDynamicSnapshotJob(snapshotAgentJob, schedule);

snapshotLocation = StartDynamicSnapshotJob(publication, subscription, snapshotLocation);

}

}

catch (Exception ex)

{

logger.Error("Failed to create the new dynamic snapshot.", ex);

throw;

}

return snapshotLocation;

}

No comments:

Post a Comment