Football-Is-My-Life Football-Is-My-Life - 17 days ago 9
C# Question

JobRunShell.cs not found

I'm using Quartz.Net to schedule Jobs. Please see my code . Why does this error occur?

I need to register the data in the database.

error :
enter image description here

I'm using this code to register 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 see :

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 @K.B. i found error. "Message = "ExecuteNonQuery: Connection property has not been initialized.". Why does this error occur?

Answer

i found 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);