Link to home
Start Free TrialLog in
Avatar of cpence
cpenceFlag for United States of America

asked on

Snapshot Replication via TSQL

OK, done some looking around, and come to a road block.

We are trying to conduct a snapshot replication dynamically using VB.net. By dynamically I am meaning, that the replication needs to be done after we update data that may not always be getting updated at the same time, one week we might have two updates, the next week we might have one update on a Monday and the following week we might have one update on a Wednesday. Our vb.net code will, after everything has been updated, execute the sp_start_job SQL command to regenerate the snapshot for our "Snapshot" publication, and then it runs the sp_update_schedule SQL command to update the date that the task will execute. I have the Jobs in place to generate the new snapshots and the vb.net code that runs the sp to start the snapshot agent, and the vb.net code to update the schedule for the job.

What i am missing it the TSQL to "Reinitialize" the subscription to the replication does not fail when the distribution agent runs. I received the following error in my job history log for the distribution agent task: "The subscription(s) have been marked inactive and must be reinitialized. NoSync subscriptions will need to be dropped and recreated."

I have include the vb.net code, if it helps, omitting sensitive info like server names and such.  Any assistance would be appreciated.

Thanks
''vb.net code
  Dim command As New SqlClient.SqlCommand("EXEC msdb.dbo.sp_start_job N" & snapshotJob, localConnection)
        Dim snapshotResults As Integer = Nothing

        localConnection.Open()
        snapshotResults = command.ExecuteNonQuery()
        localConnection.Close()


        command = New SqlClient.SqlCommand("EXEC msdb.dbo.sp_update_schedule @name =" & replicationJobScheduler & ", @enabled = 1,@freq_interval =1, @active_start_date =" & runDate & ", @active_start_time=233000", localConnection)
        localConnection.Open()
        snapshotResults = command.ExecuteNonQuery()
        localConnection.Close()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial