Click to See Complete Forum and Search --> : How to run a code for one user only ?
hndlogic
01-26-2007, 09:06 AM
Hello
I have a code which runs only once a day. Its working fine. But the problem is that it runs more than once for a day.
Suppose that code is not run for today. And 10 visitors simultaneously accesses that page, the code runs 10 or more than one times.
I want this code run only once not for all requests. Any ideas ?
Ribeyed
01-26-2007, 10:40 AM
what is the code doing?
lmf232s
01-26-2007, 02:29 PM
Do you also need to have this code ran and execute in a web page?
You could take the code and put it in a .vb file and then have a schedule task run it once a day at a predetermined time.
hndlogic
01-27-2007, 12:37 AM
The code is doing a few updates in the database. It runs once a day. I am handling this (running once) by storing the script running date in a a table of my DB. I am calling this code in my default.aspx. It checks the server date and last code running date in the DB and runs the code if not run for today.
I can call this code in my global.asax (Session Start event) but this is the same situation. The code can run more than once. If I place it in Application Start event, the code may not run on daily basis.
What should I do ? I dont have the facility of task scheduling on the server.
hndlogic
01-27-2007, 12:38 AM
The tasks running on database may take time. Thats why its running for more than one visitor.
hndlogic
02-06-2007, 03:17 AM
Is there anyone who can help me in this ? Or you all are juniors.
Ribeyed
02-06-2007, 03:56 AM
Can you not just create a trigger in SQL Server to handle it?
Ribeyed
02-06-2007, 10:04 AM
If the code is affecting only the database and you are using a DBMS that
supports batch jobs, place the call to the code in a batch job then schedule
that.
If you are running a database that doesn't support jobs, create a shell
script or windows task that will run the code and then schedule that to run
once a day.
hndlogic
02-07-2007, 12:50 AM
Dear Ribeyed, I know you are absolutely right. But there on hosting server I dont have the facility of task scheduling and process batch jobs in SQL server.
I have mentioned it before. What I am thinking that is there anything I can do with the Application Object or some DB transaction ? Don't know exactly.
sniper
02-07-2007, 08:15 AM
You could try creating a log table in your db and then get the app to run when you want it to run. When your app runs you can then have it insert the date and whatever other information you want in the log table. Obviously before inserting into the log table you will check to see if that days date has already been enterred. Hope that helps.