Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am making a website in which i need to automatically call some method at 23:59 and update database.
Posted
Updated 26-Jan-15 3:59am
v2
Comments
jaket-cp 26-Jan-15 10:00am    
Maybe consider using SQL Server Agent: https://msdn.microsoft.com/en-GB/library/ms189237.aspx
DamithSL 26-Jan-15 10:08am    
what is your database server? what is the task your method perform and which data it depends on?
Ashutosh Tripathi 26-Jan-15 10:20am    
static void Main(string[] args)
{


//Time when method needs to be called
var DailyTime = "18:51:00";
var timeParts = DailyTime.Split(new char[1] { ':' });

while (true)
{

var dateNow = DateTime.Now;
var date = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, int.Parse(timeParts[0]), int.Parse(timeParts[1]), int.Parse(timeParts[2]));
TimeSpan ts;
if (date > dateNow)
{
ts = date - dateNow;
}
else
{
date = date.AddDays(1);
ts = date - dateNow;
}

//waits certan time and run the code
Task.Delay(ts).Wait();
SomeMethod();

}
}



static void SomeMethod()
{
Datalayer obj = new Datalayer();
obj.AutoCalculate();

}

public void AutoCalculate()
{
var t = from a in da.tree_details
where a.userid=="RA1051"
select a;
foreach (tree_detail k in t)
{
k.lcount = 10;
}
da.SubmitChanges();
}

1 solution

You will not do this at the website level.
Write an SQL job that executes at the allocated time and runs the desired stored procedure.

For more information, try -
Schedule a Job[^]
Create a Transact-SQL Job Step[^]
Create and Schedule jobs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900