"aido" <acreegan@hotmail.com> wrote in message
news:%23TGsbkw9DHA.2368@TK2MSFTNGP11.phx.gbl...
> I have been dancing this crazy dance all week. This code works for me
(c#)
> however I have a problem with the CurrentRunStatus permanently returning
> Idle if anybody out there knows why. Hope this helps though can't promise
> it is the correct way of doing things.
>
> Aido.
>
> // Connect to the database.
>
> SQLDMO.SQLServer2Class svr = new SQLDMO.SQLServer2Class();
>
> svr.Connect("(local)", "sa", "sapassword");
>
>
>
> // Iterate through pull subscriptions
>
> SQLDMO.ReplicationDatabase dbase =
> svr.Replication.ReplicationDatabases.Item("DatabaseName");
>
> SQLDMO.MergePullSubscriptions pullsubs = dbase.MergePullSubscriptions;
>
> for(int pullsubidx = 1; pullsubidx <= pullsubs.Count; pullsubidx++)
>
> {
>
> SQLDMO._MergePullSubscription pullsub = pullsubs.Item(pullsubidx);
>
> // Find the job matching the subscriptions job id
>
> SQLDMO._Job job = null;
>
> for(int jobidx = 1; jobidx <= svr.JobServer.Jobs.Count; jobidx++)
>
> {
>
> job = svr.JobServer.Jobs.Item(jobidx);
>
> if (job.JobID == sub.MergeJobID)
>
> return job;
>
> }
>
> // If we have a job check whether it needs to be run
>
> if (job != null)
>
> {
>
> int date = job.LastRunDate;
>
> int time = job.LastRunTime;
>
> bool isdue = false;
>
> // date is 0 if job never run
>
> if (date == 0)
>
> isdue = true;
>
> // Otherwise compute the expiry date
>
> else
>
> {
>
> System.DateTime due = new System.DateTime(
>
> date / 10000, (date % 10000) / 100, (date % 100),
>
> time / 10000, (time % 10000) / 100, (time % 100))
>
> + new TimeSpan(Module.DatabaseSyncRate, 0, 0);
>
> isdue = DateTime.Now > due;
>
> }
>
> // Check status and reschedule if not
>
> // active and due.
>
> job.Refresh(); // Not sure whether this updates CurrentRunStatus
>
> if (job.CurrentRunStatus ==
> SQLDMO.SQLDMO_JOBEXECUTION_STATUS.SQLDMOJobExecution_Idle && isdue)
>
> {
>
> System.Diagnostics.Trace.WriteLine(String.Format("Synchronizing
> database '{0}'", job.Name), "Replicator Trace");
>
> job.Start(Type.Missing);
>
> }
>
> "Chandrasekar Gopalan" <chandra@online.microsoft.com> wrote in message
> news:8AoXwbl8DHA.1152@cpmsftngxa07.phx.gbl...
> > Hi -
> > Also the sample codes are shipped with the SQL server CD. Do a
> > custom install of sample codes if not done already. The default location
> of
> > replication DMO sample code is : %program files\Microsoft SQL
> > server\80\Tools\DevTools\Samples\sqlrepl.
> >
> > For information on how to use these sample codes are available in books
> > online. Search for "programming replication" in BOL.
> >
> > Regards,
> > Chandra
> > --------------------
> > ||Content-Class: urn:content-classes:message
> > ||From: "Paul Ibison" <anonymous@discussions.microsoft.com>
> > ||Sender: "Paul Ibison" <anonymous@discussions.microsoft.com>
> > ||References: <54B7C8A3-08BF-4887-AECC-91C8A296CDEB@microsoft.com>
> > ||Subject: Automating replication using sqldmo
> > ||Date: Fri, 13 Feb 2004 05:21:46 -0800
> > ||Lines: 6
> > ||Message-ID: <f48201c3f234$546b3880$a301280a@phx.gbl>
> > ||MIME-Version: 1.0
> > ||Content-Type: text/plain;
> > || charset="iso-8859-1"
> > ||Content-Transfer-Encoding: 7bit
> > ||X-Newsreader: Microsoft CDO for Windows 2000
> > ||X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
> > ||Thread-Index: AcPyNFRrQvl7MA+XRDeB8cvxxd2u+A==
> > ||Newsgroups: microsoft.public.sqlserver.replication
> > ||Path: cpmsftngxa07.phx.gbl
> > ||Xref: cpmsftngxa07.phx.gbl
microsoft.public.sqlserver.replication:47307
> > ||NNTP-Posting-Host: tk2msftngxa11.phx.gbl 10.40.1.163
> > ||X-Tomcat-NG: microsoft.public.sqlserver.replication
> > ||
> > ||If you want to run the agents programatically, have a look
> > ||at the activex controls. There is some sample code on MSDN
> > ||(
http://msdn.microsoft.com/library/default.asp? > > ||url=/library/en-us/replprog/rp_replsamp_5a9f.asp).
> > ||Regards,
> > ||Paul Ibison
> > ||
> >
>
>