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 am facing an issue while trying to write the custom Timer Job in SharePoint 2007.

Have overridden the Execute method

public override void Execute(Guid contentDbId)
    {
        using (SPSite oSPsite = new SPSite("http://esssharepoint20"))
        {
            oSPsite.AllowUnsafeUpdates = true;

            using (SPWeb oSPWeb = oSPsite.OpenWeb())
            {
                SPList splist = oSPWeb.Lists["PhoneBook"];

                SPListItem spItem = splist.Items.Add();

                spItem["PhoneNumber"] = DateTime.Now.ToString();

                spItem.SystemUpdate();

            }
            oSPsite.AllowUnsafeUpdates = false;
        }

    }

and registering the Job using a Feature

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        //string oSPsiteURL = (properties.Feature.Parent as SPSite).Url;

        using (SPSite phoneBookSite = properties.Feature.Parent as SPSite)
        {
            SPWebApplication phoneBookApplication = phoneBookSite.WebApplication;
            SPJobDefinitionCollection timerJobCollection = phoneBookApplication.JobDefinitions;

            SPDailySchedule jobSchedule = new SPDailySchedule();

            jobSchedule.BeginHour = 0;
            jobSchedule.BeginMinute = 0;
            jobSchedule.BeginSecond = 0;

            jobSchedule.EndHour = 2;
            jobSchedule.EndMinute = 30;
            jobSchedule.EndSecond = 0;

           phoneBookPurgeData phoneBookTimerObj = new phoneBookPurgeData(
                "PhoneBook Timer Job",
                phoneBookApplication
                );

            phoneBookTimerObj.Schedule = jobSchedule;

            timerJobCollection.Add(phoneBookTimerObj);
            phoneBookApplication.Update();

        }
        //throw new Exception("The method or operation is not implemented.");
    }

however it throws the below error:

08/09/2011 22:29:30.60 Timer 7psa Critical The Execute method of job definition PhoneBookTimerJob.phoneBookPurgeData (ID 2519a803-af39-4a2a-ae42-8d177a609ed8) threw an exception. More information is included below. Value cannot be null. Parameter name: uriString

08/09/2011 22:29:30.60 OWSTIMER.EXE (0x097C) 0x0C7C Windows SharePoint Services Timer 72ae Unexpected Exception stack trace: at System.Uri..ctor(String uriString) at Microsoft.SharePoint.SPSite..ctor(String requestUrl) at PhoneBookTimerJob.phoneBookPurgeData.Execute(Guid contentDbId) at Microsoft.SharePoint.Administration.SPTimerJobInvoke.Invoke(TimerJobExecuteData& data, Int32& result)

Webapplication is still exists, what am I doing wrong? and how to fix this?

share|improve this question
    
Could you post data on the custom class phoneBookPurgeData as it seems this is what fails –  Anders Rask Aug 9 '11 at 18:28

2 Answers 2

Check that the site exist in PowerShell or in a console application

$site = Get-SPSite http://esssharepoint20

Just to be sure

share|improve this answer
    
If it wasn't there it would throw a FileNotFoundException, right? –  Rob D'Oria Aug 9 '11 at 17:51
    
Thank you. Helped in solving my issue. –  Pradeep Apr 3 at 7:11
up vote 3 down vote accepted

After fighting with the error created a new dll with the same code and it works like a champ.

share|improve this answer
    
i made a small mistake while building the dll first time and kept it in the GAC. However realised and re-compiled, removed the old dll from the GAC, restarted IIS and added the updated dll into the Gac but still it was refering to the old dll and ended up with creating a new dll. –  Karthikeyan Aug 9 '11 at 18:52
1  
When working with timer jobs you have to restart the SharePoint Timer Service for your changes to take effect. Restarting the IIS won't help much, as the DLLs are loaded and cached by the timer service. To restart the service, you can call "net stop sptimerv3" and "net start sptimerv3". For SharePoint 2010 it's "sptimerv4". –  Robert Aug 9 '11 at 20:14

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.