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:
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 to share