JobRunShell.cs not found

I am using Quartz.Net to schedule Jobs. Check out my code. Why is this error occurring?

I need to register data in a database.

mistake: enter image description here

I am using this code to log data:

public class NewsSchedule : INewsSchedule
{
    public void Run(int minute)
    {
        DateTimeOffset startTime = DateBuilder.FutureDate(2, IntervalUnit.Second);

        IJobDetail job = JobBuilder.Create<NewsJob>()
                                   .WithIdentity("newsJob")
                                   .Build();

        ITrigger trigger = TriggerBuilder.Create()
                                         .WithIdentity("trigger1")
                                         .StartAt(startTime)
                                         .WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever())
                                         .Build();

        ISchedulerFactory sf = new StdSchedulerFactory();
        IScheduler sc = sf.GetScheduler();
        sc.ScheduleJob(job, trigger);

        sc.Start();
    }
}
public interface INewsSchedule
{
    void Run(int minute);
}
public class NewsJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        var sqlConnection = new SqlConnection("Data Source=.;Initial Catalog=NewsApk;Integrated Security=SSPI;");
        sqlConnection.Open();
        var sqlCommand = new SqlCommand("Insert into JN_NewsCategories(NewsCategoriesFr,NewsCategoriesEn,IsGetNews)Values(@1,@2,@3)");
        sqlCommand.Parameters.AddWithValue("@1", "test");
        sqlCommand.Parameters.AddWithValue("@2", "test2");
        sqlCommand.Parameters.AddWithValue("@3", false);
        sqlCommand.ExecuteNonQuery();
        sqlConnection.Close();
    }
}

      

Update:

Please look:

The Select command works correctly, but the Register command does not work.

public class NewsJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        var sqlConnection =
            new SqlConnection("Data Source=.;Initial Catalog=NewsApk;Integrated Security=SSPI;");
        sqlConnection.Open();
        var sqlCommand =
            new SqlCommand(
                "Insert into JN_NewsCategories(NewsCategoriesFa,NewsCategoriesEn,IsGetNews)Values(@1,@2,@3)");
        sqlCommand.Parameters.AddWithValue("@1", "test");
        sqlCommand.Parameters.AddWithValue("@2", "test2");
        sqlCommand.Parameters.AddWithValue("@3", false);

        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from JN_NewsCategories", sqlConnection);
        DataTable dataTable = new DataTable();
        sqlDataAdapter.Fill(dataTable);// 12 record found. its ok.

        sqlCommand.ExecuteNonQuery();

        sqlConnection.Close();
    }
}

      

thanks @KB I found a bug. "Message =" ExecuteNonQuery: Connection property was not initialized. ". Why does this error occur?

+3


source to share


3 answers


I found the answer.

replace this:

 var sqlCommand = new SqlCommand("Insert into JN_NewsCategories(NewsCategoriesFa,NewsCategoriesEn,IsGetNews)Values(@1,@2,@3)");

      



with this:

 var sqlCommand = new SqlCommand("Insert into JN_NewsCategories(NewsCategoriesFa,NewsCategoriesEn,IsGetNews)Values(@1,@2,@3)",sqlConnection);

      

+1


source


This issue came from a database connection or something database related, Nothing to do with Quartz.



+1


source


It is not an issue that says it cannot find pdb for Quartz, to overcome this, you have 2 options:

  • Download project source code and point it
  • or from menu -> tools -> options -> debugging-> general and make sure you check Enable Just My Code

enter image description here

0


source







All Articles