开发者

NCron - cannot see job

开发者 https://www.devze.com 2023-02-13 07:18 出处:网络
I want to be able to run a function that deletes from my database every say minute. I would use a SQL job, but I only have the resource of SQL Server 2008 Express. So I am using an ncron job (which I

I want to be able to run a function that deletes from my database every say minute. I would use a SQL job, but I only have the resource of SQL Server 2008 Express. So I am using an ncron job (which I havnt too much experience with).

My code is:

namespace ConsoleApplication2_ncron
{
    class Program
    {
        static void Main(string[] args)
        {
            Bootstrap.Init(args, ServiceSetup);
        }

        static void ServiceSetup(SchedulingService service)
        {
            //service.Hourly().Run<doStuff>();

            service.At("* * * * *").Run<ConsoleApplication2_ncron.doStuff>();
        }
    }
}

And my doStuff.cs file is

namespace ConsoleApplication2_ncron
{
    class doStuff : NCron.CronJob
    {
        public override void Execute()
        {
            SqlConnection conn = new SqlConnection();
            conn = new SqlConnection(ConfigurationManager.AppSettings["strConnectionString"].ToString());

            conn.Open();

            SqlCommand command = conn.CreateCommand();
            command.CommandText = "res_delete_old_records";
            command.CommandType = CommandType.StoredProcedure;

            command.ExecuteNonQuery();
            // close the connection
            conn.Close();

            throw new NotImplementedException();
        }
    }
}

However, when I execute the following on the command line (in order to test before I put on server):

consoleApplication2_ncron exec doStuff

I get the follow开发者_Python百科ing:

No job is registered with the name "doStuff"


In order to be able to execute a job using the ncron.exe exec jobName command syntax, you will need to register the name for the job during initialization:

service.At("* * * * *").Run<JobType>().Named("jobName");
0

精彩评论

暂无评论...
验证码 换一张
取 消