1
votes

I have created a Timer Job and deployed the wsp to the central admin. The feature is installed and activated fine. I don't get any error. But i can't see the timer job in the Timer job list in central admin. I dont see the feature in the site collection feature either.

1)I did install and activate the features using STSADM commands. 2) The Timer job does not appear under Job Definitions in sharepoint manager. The feature however does appear under the Feature definitions in sharepoint manager

The Webapplication has three site collections and each site collection has a separate database database

I dont get any error while install or activating the feature.

MY code is as follows
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace TestTimer
{
    public class TestTimerJob:SPJobDefinition
    {
        public TestTimerJob() : base() 
        {


    }
    public TestTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)
        : base(jobName, service, server, targetType)
    {
        this.Title = "Test Timer Job";

    }
    public TestTimerJob(string jobName, SPWebApplication webApplication)
        : base(jobName, webApplication, null, SPJobLockType.Job)
    {
        this.Title = "Test Timer Job";
    }

    public override void Execute(Guid targetInstanceId)
    {
        try
        {
            SendEmail();
        }
        catch (Exception ex)
        {
            LogError(ex.InnerException.ToString(), ex.StackTrace + ex.Source);
        } 
    }
    private void SendEmail()
    {
        try
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

            //msg.To.Add(ToEmailAddress);
            msg.To.Add("****");
            msg.From = new System.Net.Mail.MailAddress(""********";");
            msg.Subject = "Subject";

            msg.IsBodyHtml = true;
            string EmailBody = " <b>Welcome to Send an Email!!</b><p> Example.<BR>";
            msg.Body = EmailBody;
            string smtp = "***";
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(smtp);
            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
            NetworkCred.UserName = "********";
            NetworkCred.Password = "********";
            NetworkCred.Domain = "********";
            client.Credentials = NetworkCred;
            client.Send(msg);
        }
        catch (Exception ex)
        {

            LogError(ex.InnerException.ToString(), ex.StackTrace);
        }





    }


}

}

  Feature Reciever code below
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Data.SqlClient;
namespace TestTimer
{
    class TestTimerReceiver : SPFeatureReceiver
    {
        const string SYNC_JOB_NAME = "My_Timer_Job";
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPWebApplication webapp = (SPWebApplication)properties.Feature.Parent;
                foreach (SPJobDefinition job in webapp.JobDefinitions)
                {
                    if (job.Name.ToLower()==SYNC_JOB_NAME.ToLower())
                    {
                        job.Delete();
                    }
                }

            TestTimerJob timerJob = new TestTimerJob(SYNC_JOB_NAME, webapp);
            SPMinuteSchedule schedule = new SPMinuteSchedule();
            schedule.BeginSecond = 0;
            schedule.EndSecond = 59;
            schedule.Interval = 5;
            timerJob.Schedule = schedule;
            timerJob.Update();
        }
        catch (Exception ex)
        {

        }
    }

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
        try
        {
            SPWebApplication webapp = (SPWebApplication)properties.Feature.Parent;
            foreach (SPJobDefinition  job in webapp.JobDefinitions)
            {
                if (job.Name.ToLower()==SYNC_JOB_NAME.ToLower())
                {
                    job.Delete();
                }
            }
        }
        catch (Exception ex)
        {

        }
    }

    public override void FeatureInstalled(SPFeatureReceiverProperties properties)
    {

    }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {

        }
    }
}

and Feature .xml below

<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="b4fa9cf0-dba9-4206-a37c-e707af6199f9"
          Title="TestTimerReceiver"
          Description="Description for TestTimerReceiver"
          Version="12.0.0.0"
          Hidden="FALSE"
          Scope="Site"
          DefaultResourceFile="core"
          ReceiverAssembly="TestTimer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7f9249145d98c2ad"
          ReceiverClass="TestTimer.TestTimerReceiver"



          xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>
  </ElementManifests>
</Feature>
1
Try an IISReset on the web server.gurkan
Try restarting the SharePoint Timer service (sptimerv3). you can do it from the command line like: net stop SPTimerV3 / net start SPTimerV3gurkan

1 Answers

0
votes

Also try clearing the Sharepoint server cache