0

How can I execute a stored procedure every one hour by using .net code?

(Stored procedure should be executed automatically for every one hr)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Software Enginner
  • 675
  • 2
  • 14
  • 43
  • 7
    Use an sql server job. They are meant for such tasks – nunespascal Jul 09 '12 at 13:13
  • 2
    Is there a reason you can't use a SQL job? If not, you probably want a service rather than a .NET app - since a service will be automatically started on startup and will be transparent to the user – Charleh Jul 09 '12 at 13:13
  • You could just use and app and use the windows scheduler to run it every hour. Or sql server jog as recommeneded above. – paparazzo Jul 09 '12 at 13:18
  • @All, Am ready to use .net or sql code to complete this task. Thank You. – Software Enginner Jul 09 '12 at 13:22
  • Duplicate of http://stackoverflow.com/questions/2342935/how-to-schedule-a-stored-procedure – STW Jul 09 '12 at 14:16

3 Answers3

6

Create a SQL Server Agent job

.net processes are too expensive in terms of memory for such tasks.

If you really need to run a .net application, look out for scheduled tasks. Windows task scheduler is good for such tasks.

nunespascal
  • 17,584
  • 2
  • 43
  • 46
1

First you need to write a Windows service and set it to run every hour.

Calling a stored procedure from c# code can be done Like this.

I haven't posted any code myself becuase I can't find any code in your question as well. A little effort will get you a long way

Community
  • 1
  • 1
Ivan Crojach Karačić
  • 1,911
  • 2
  • 24
  • 44
1

As commented, best option is to create an SQL agent job. From Microsoft MSDN, to create a SQL Server Agent job:

  1. Execute sp_add_job to create a job.
  2. Execute sp_add_jobstep to create one or more job steps.
  3. Execute sp_add_schedule to create a schedule.
  4. Execute sp_attach_schedule to attach a schedule to the job.
  5. Execute sp_add_jobserver to set the server for the job.

More on the subject

Yaroslav
  • 6,476
  • 10
  • 48
  • 89