sql-serverreplicationsnapshot

Snapshot Replication error "Specified cast is not valid"


I am running SQL Server, version 14.0.3460.9

The "Run agent" step in my replication job throws error "Specified cast is not valid"

I do not get an error directly executing sp_helppublication.

I am trying to narrow down a specific offending article, but so far no success.

I am finding this error condition very obscure - has anyone encountered this before?

Initially creating the snapshot for a publication does not throw this error. This only happens on the scheduled sync.


Solution

  • What was happening for me is the source DB was being restored daily from a backup. So the publication on that DB did not exist when the agent was awakened via job.

    It would have saved me a lot of time had the message been clearer!

    My solution was to use the scripts that can be generated from the same SSMS wizard that sets up the replication to re-erect it via a couple of steps (one to set up replication, one to set up my subscriber) to run right after restore.