I want to copy one row from table A to table B per hour on my asp.net website. How can I do that? Do I need win32 application? I would like to avoid that.
This sounds like you want to create a stored procedure and use the Sql Server Jobs scheduler to run it every hour. See here for details of setting that up
Or if you are using Sql Express see this question "How to run a stored procedure every day in SQL Server Express Edition?"
Ideally you wouldn't do this using IIS etc, unless there is some reason you don't have access to the database.
You can use Timer.
If you use SQL Server you can also schedule a job on the DB directly.
I would agree with brodie. Alternativly create a SSIS package and run either as a SQL Job or a scheduled task from command line(using DTEXEC).
http://msdn.microsoft.com/en-us/library/ms365302.aspx - Shows you how to create a basic solution.
http://decipherinfosys.wordpress.com/2008/09/17/scheduling-ssis-packages-with-sql-server-agent/ - Shows you how to schedule your task.
For your exercise either would do the trick. I would suggest using either that you feel more familiar with. But certainly wouldnt suggest creating a timer driven service.
You could create a webpage that accomplishes this and use a free service like pingdom.com to call that page every hour.
EDIT:
Mine is the easy route, probably not the best solution but quick and simple
You can check this out also:
https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
see this example for creating a new thread in global asax, http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax
Be aware though if the website goes down the process will not continue to run, if this is a problem a sql batch job or windows service would be better suited, and if the task is resource intensive it would be better to do this on another machine anyway as the global asax method will take away processing resources from your website
Related
I am using an ASP.NET web form and I have two fields Start_date and End_date in it.
I want to update a particular field in SQLServer once when the time goes beyond the End_date (i.e. the deadline is expired).
e.g. if the End_date is on 06/09/2015, then the SQLServer field should be updated as Expired at 12.01 AM on 06/10/2015.
I am new to ASP.NET and please let me know if you have any ideas. Thank you
There are way too many ways to do such thing. I.e:
making a SQL script that does that and adding that script as scheduled job in SqlServer
or, creating a WindowsService that sleeps and wakes up every hour or six and checks for expired records
or, adding a module like Hangfire to your ASP application and adding such scheduled task there
..
Those three are probably the most often used.
Anyways, it's always about some scheduler and some job to do periodicaly. Think how to write one "run" of the job (find expired, mark/delete them), then read about what schedulers you can use, then glue it together and configure the scheduler and done.
There are several ways to do this, but if all you need to do is make database changes at a given time, then I recommend using the SQL Server Agent. You can set it up to run just once or on a recurring schedule and you can set it up to run a stored procedure or you can feed it straight SQL commands.
I want to run a timely based query that will run every day at a given time.
How can I do it?
Can it be possible with trigger?
You can use SQL Server Agent job & make schedule to recurring job every day at your desired time.
As per your requirement in SQL Server you should go for SQL Job.
It is fairly simple to set up, create your query as a stored procedure and while configuring your job in step write
EXEC YourStoredProcedureName
You can set a job in SQL Server using SQL server Management Studio. It needs additional rights to view that section in management studio so if not visible you can ask admin guys to give access.
Various database systems have different mechanisms of performing Jobs and in fact both Oracle and SQL Server have jobs that - in easiest scenario - will run a procedure at particular period of time and may be recurring or not.
If you don't have enough access to the SQL Server, you can always explore outside database scenarios. On Windows you have Windows tasks which can periodically run simple console application that could run whatever query you want. On Linux you have CRON that can work similarly. The built-in functionality is - however - preferred.
Yes it is possible. Create cron job for it.
check this: http://blog.bobcravens.com/2009/10/an-event-based-cron-scheduled-job-in-c/
I'm in the process of building a Scheduler in C sharp. The scheduler should ping the DataBase Queue and if anything new is written in the Database it should pick that up and send it to the remote server for processing. (The files will be uploaded to the database by the client using a WCF webservice) how do you guys think i should handle this situation? any type of help would be highly appreciated. I'm still in the design phase.
Thanks.
As this is a periodic task, I'd consider writing an app that does the job when run (with no scheduling). Then add it to the Windows Task Scheduler.
Take a look at Quartz.NET. It easily lets you set up a scheduler and plug in Jobs (i.e. Send the files to the remote server) and Triggers (How often do you want it to run..) It has an excellent Fluent API as well as support for CRON style expressions.
There are also tutorials on the site, and google will find you a bunch more.
#spender's idea is easy to implement. Another option is using a database trigger to call CLR proc
http://msdn.microsoft.com/en-us/library/ms131094%28v=SQL.90%29.aspx
Can I call a C# function by a SQL Server trigger?
I've wrote a Restaurant Management application.
I have a Database based on SQL Server 2005 which has one table named OrdersItems. Every 5 minutes I want to read all rows of this table and based on a specific criteria Update some fields.
I don't want to do that in my main application and I prefer to have an Alternative engine to perform this.
Which method is the best method to perform such task ? Also note that this Table (OrdersItems) is under process every time because main application must be always running and get new Restaurant Orders.
You can create a SQL Server Agent job that does the update every five minutes.
If you are using SQL Server Express edition, you can't use SQL Server Agent because it's only included in the "bigger" versions of SQL Server.
In this case, you can create your jobs manually using batch files and Windows Task Scheduler.
I definitely agree with Christian and dougajmcdonald's points about using SQL Task/ Maintenance. However since you included c# in your tags an alternative is to create a Windows Service.
The benefits of this approach
Can run on a machine that doesn't have the SQL Server Agent installed (including express editions)
Can be run outside the context of a user login.
Has standard stop start pause continue mechanism that's well understood.
If the service itself fails will likely result in an event log
This answer contains a template for a windows service that periodically gets data and executes. You may simply want to change the DoStuff method to execute a stored procedure
Create a dialog timer and let it activate a stored procedure. This has the advantage of being fully contained inside the database (no external process), it does not require SQL Agent (runs on Express) and is completely crash resilient at the point it will survive database detach/attach and backup/restore operations (the scheduled job will run after recovery on the new restored database).
I would expect a SQL Task / Maintenance plan would be the best for this.
You can set them up for whatever interval you want, specifying a SQL statement, maintenance task etc you want to run.
You can also setup alerts etc if you want to know when it fails for example.
Deploy a cron job on a server with access to the database which is started every 5 minutes and processes your data, using transactions. I see one problem there: If the amount of data to be processed is large, it could quite work more than five minutes.
Here's an interesting problem. I have an ETL script written in c# that I have been running manually on a somewhat regular basis. It is used to update my web app's database.
I want to automate the ETL process AND create an interface for the web app admins to manually start the ETL process.
I could have sql server kick off the ETL process on a schedule and implement a button or something on a web page that will do the same thing, but I don't want to put my code in 2 different places because I don't want to update it in 2 places when it changes. But I don't know how to make my web app tell SQL server to manually start a scheduled process. Can this be done?
OR
I could somehow implement the scheduling in the web app itself, but by now most people are familiar with the problems that are faced when trying that (app may not be running at certain times, must wait on request to start a process (without some trickery)). Also, since the ETL process takes a while, I don't want to make some poor end user wait on a response, so it would definitely have to use a new thread.
What else could I do? What would you do?
You mentioned you are using SQL Server. What version is it? Is SQL Server Integration Services (which is the full-blown ETL tool for the platform) an option for you? If you want scheduled Extraction, Transformation and Load jobs, SSIS is a great tool on the Microsoft platform and is included in most SQL Server licenses.
Or, check out Quartz.