Thursday, February 26, 2015

How can I create a one time cron schedule that would execute only once in C#?

I have used cron schedule in C# to create an application that should trigger a job only once. This code piece is throwing an exception, An unhandled exception of type 'Quartz.SchedulerException' occurred in Quartz.dll


Below is my code:



class Program
{
static void Main(string[] args)
{
Test();
}

public static void Test()
{
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
IScheduler scheduler = schedulerFactory.GetScheduler();

IJobDetail jobDetail = JobBuilder.Create<SatellitePaymentGenerationJob>()
.WithIdentity("TestJob")
.Build();
Console.WriteLine(DateBuilder.DateOf(16, 30, 00, 24, 2, 2015));
//ITrigger trigger = TriggerBuilder.Create()
// .ForJob(jobDetail)
// .WithCronSchedule("0 0 12 20 4 ? *")
// .WithIdentity("TestTrigger")
// .StartNow()
// .Build();
ITrigger trigger = TriggerBuilder.Create()
.WithDescription("Once")
.WithSimpleSchedule(x => x.RepeatForever().WithRepeatCount(1))
.StartAt(DateBuilder.DateOf(12, 43, 00, 26, 2, 2015))
.Build();

scheduler.ScheduleJob(jobDetail, trigger);
scheduler.Start();
}
}

internal class SatellitePaymentGenerationJob : IJob
{
public void Execute(IJobExecutionContext context)
{
Console.WriteLine("test");
}
}

I believe that the way I have done scheduling to be execute only once is causing the issue. Please advice.





mayooran99


Switch with Regex

Hi,


I'm having some trouble replicating this powershell code in C# could anyone give me a hand or point me in the right direction?


Powershell:



$FirstLetter = $Promoter.Substring(0,1)
Switch -Regex ($FirstLetter)
{
"[A-G]" {"A - J"}
"[K-Z]" {"K - Z"}
}





If this is helpful please mark it so. Also if this solved your problem mark as answer.


Switch with Regex

Figured it out:



Regex regex = new Regex(@"[A-Z]");
Match match = regex.Match(FirstLetter);

if(match.Success)





If this is helpful please mark it so. Also if this solved your problem mark as answer.


Switch with Regex

Hi TenPart,


I am glad to know you solved this problem and thanks for sharing the solution.


It will be very beneficial for other community members who have the similar questions. Thanks.




Best regards,


Kristin






We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Click HERE to participate the survey.


How is it possible to use Index Seek for LIKE %search-string% case?

Lesha if you add OPTION (RECOMPILE) do you get different plan?


Best Regards,Uri Dimant SQL Server MVP, http://ift.tt/1iQ9JkR



MS SQL optimization: MS SQL Development and Optimization

MS SQL Consulting: Large scale of database and data cleansing

Remote DBA Services: Improves MS SQL Database Performance

SQL Server Integration Services: Business Intelligence


How is it possible to use Index Seek for LIKE %search-string% case?


Lesha if you add OPTION (RECOMPILE) do you get different plan?



Yra, yes, of course. It is because RECOMPILE query hint forces the query optimizer to recompile the query plan each time. So, for:



EXEC dbo.USP_SAMPLE_PROCEDURE N'%94'

the plan includes Index Scan operation which is the ONLY possible way to resolve the query, in my point of view.



PS: I still don't understand how Index Seek can be used to resolve that query.




Alexey



How is it possible to use Index Seek for LIKE %search-string% case?

SQL Server optimizer just uses a cached plan, issue first


DBCC DROPCLEANBUFFERS


go


EXEC dbo.USP_SAMPLE_PROCEDURE N'%94'


And you will CI scan in both executions




Best Regards,Uri Dimant SQL Server MVP, http://ift.tt/1iQ9JkR



MS SQL optimization: MS SQL Development and Optimization

MS SQL Consulting: Large scale of database and data cleansing

Remote DBA Services: Improves MS SQL Database Performance

SQL Server Integration Services: Business Intelligence