Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

i wrote a stored procedure for deleting item from database..please tell me how to call it automatically.i am using ASP with it
Posted
Comments
Philip Stuyck 14-Aug-12 1:41am    
What do you mean by automatically ? Should it be called periodically without user intervention, or do mean that you don't know how to call it via a program ?
[no name] 14-Aug-12 1:45am    
ya i want to call that procedure after every 10 mins..i don't know how to do that..
Aarti Meswania 14-Aug-12 2:00am    
which parameters you are passing in stored-procedure?
[no name] 14-Aug-12 2:02am    
ALTER procedure [dbo].[del](
@exp_date datetime
)
AS
begin

delete from email_data where exp_date < GETDATE() and active=1
end

This id the procedure but i need a condition to run it automatically.
Aarti Meswania 14-Aug-12 4:39am    
ok open sql server 2005, and right hand side check can you see there 'SQL SERVER AGENT'?
and please use reply tag because 'have a question...' will button not give me gmail alert so, that i can not get you have posted reply :)
you are using sql so, easy way by setting job you can achieve this.
second way is to create windows service and install it at server. but sql-job will fullfill your requirement with in 5 minutes.

Refer: http://msdn.microsoft.com/en-us/library/ms189915.aspx[^]

and this search[^] will give you all details.
 
Share this answer
 
Comments
[no name] 14-Aug-12 2:37am    
Please tell me any other kind of solution for this..I am explaining the scenario:

I am having one user table..at the time user get register to the website that time i am saving to table and i am sending username and password to his/her email id.now after getting the details if within 30 min the user don't login to the system using that username and password then i have to delete that entry from the database autometically
Dear try to use trigger such scenario which will check for the event to be occurs and trigger get fires.
Thank you.
 
Share this answer
 
Comments
[no name] 14-Aug-12 4:01am    
can u plz tell me how to do that or any link which will help coz i don't have idea about triggers
Prasad_Kulkarni 3-Sep-12 6:43am    
Countered, +5
1. Write the stored procedure which will delete all the user rows from database who are ' not active' and 'registered more than 30 minutes ago' ( as per your requirement).

2. Create SQL server job that will execute your stored procedure. Read about SQL jobs here http://msdn.microsoft.com/en-us/library/ms191439.aspx[^] and here http://www.sqlteam.com/article/scheduling-jobs-in-sql-server-express[^]. The job can be scheduled to run periodically after a specific interval ( say every 10 minutes in your case).
 
Share this answer
 
v3
There are many ways to do this :-

(1) Set it up as a scheduled job under management-->SQL Server Agent-->Jobs in Enterprise Manager.

(2) you can use the command line sqlcmd.exe and simply write batch files that you schedule in windows scheduled tasks.

(3) You can take the help of timer which will call the stored procedure from Asp.net .
 
Share this answer
 
Comments
[no name] 14-Aug-12 5:07am    
if possible plz give me some example..

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