Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom job. It works fine on staging server, after moving to production it is not working. It shows in Central Administration "Job Definitions" I can open it and click "Run now" but it has no effect = still is visible in "Job Definitions" and not visible in "Job History" or "Running jobs"

I have:

  • restarted OWSTIMER
  • iisresets
  • browsed ULS for info (no info)
  • checked event viewer (no info)

The difference between staging and production is that staging contains only one webapplication and production more.

Could it be that SPJobLockType.ContentDatabase is wrong here? Or is it something else?

Jobs code:

    public class PropagacjaDanychLekuJob : SPJobDefinition
    {
        public const string JobName = "PropagacjaDanychLekuJob";

        [Persisted()]
        private int _lekId;
        [Persisted()]
        private string _numerKatalogowy;
        [Persisted()]
        private string _wielkoscOpakowania;
        [Persisted()]
        private string _stezenie;
        [Persisted()]
        private double _cenaKatalogowa;
        [Persisted()]
        private DateTime _zmianaOdDaty;

        public PropagacjaDanychLekuJob(string name, SPWebApplication webApplication, SPServer server, SPJobLockType lockType) : base(name, webApplication, server, lockType)
        {
        }

        public PropagacjaDanychLekuJob(SPWebApplication webApp) : base(JobName, webApp, null, SPJobLockType.Job)
        {

        }

        public PropagacjaDanychLekuJob(SPWebApplication webApp, int lekId, string numerKatalogowy, string wielkoscOpakowania, string stezenie, double cenaKatalogowa, DateTime zmianaOdDaty)
            : base(JobName, webApp, null, SPJobLockType.ContentDatabase)
        {
            Title = "Aktualizacja po zmiane leku o Id " + lekId;

            _lekId = lekId;
            _numerKatalogowy = numerKatalogowy;
            _wielkoscOpakowania = wielkoscOpakowania;
            _stezenie = stezenie;
            _cenaKatalogowa = cenaKatalogowa;
            _zmianaOdDaty = zmianaOdDaty;

        }

        public PropagacjaDanychLekuJob() : base()
        {
        }

        #region Overrides of SPJobDefinition

        public override void Execute(Guid targetInstanceId)
        {
            SPWebApplication webApp = this.Parent as SPWebApplication;
            //SPListItem lek = webApp.Sites[0].RootWeb.Lists["Leki"].GetItemById(_lekId);

            SPSecurity.RunWithElevatedPrivileges(delegate()
                                                     {
                                                         using (SPSite site = new SPSite(webApp.Sites[0].ID))
                                                         {
                                                             using (SPWeb web = site.OpenWeb())
                                                             {
//my operations
                                                             }
                                                         }
                                                     });

        }

        #endregion
        }
}

Execution in my event receiver:

PropagacjaDanychLekuJob job = new PropagacjaDanychLekuJob(properties.Web.Site.WebApplication,
                                                                              properties.ListItemId,
                                                                              numerKatalogowy,
                                                                              wielkoscOpakowania,
                                                                              stezenie,
                                                                              cenaKatalogowa,
                                                                              DateTime.Parse(propagacjaOd));

                    //job.Execute(Guid.Empty);
                    SPOneTimeSchedule spOneTimeSchedule = new SPOneTimeSchedule(DateTime.Now);
                    job.Schedule = spOneTimeSchedule;
                    job.Update();
share|improve this question
    
Have you verified that the value of webApp is correct? Also, did you solve this problem? I have a similar situation. –  LCountee Apr 4 '13 at 18:33
    
I haven't exactly solved the problem, but I have checked all variables, logged it to sharepoint logs and was ok. You may try to add the user you need (in my case the application pool account) to Farm Administrators. –  christof Apr 5 '13 at 9:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.