scheduled asp script

This is a discussion on "scheduled asp script" within the Classic ASP section. This forum, and the thread "scheduled asp script are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 18th, 2005, 09:47
Junior Member
Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
scheduled asp script

Hi,

Is is possible to run an asp sever script according to a schedule rather than being invoked by a browser request?

Here's why (any alternative suggestions welcome):
I am building an ecommerce site where the product supplier provides access to a text document containing all currently out of stock items. The text document is updated hourly. I want to be able to run a script every hour which updates a column in my product database so that none of the products with 0 in the stock column are returned in my queries. Because of the paging of products, it would be better if products are not in the recordsets when querying the database (rather than trying to remove or skip records after the database has been queried).

I can simply invoke the script every time somebody visits the homepage for example, but I'd rather not put this burdon on the server when the user will be waiting for the page to be served. It would be better if the database is continuously updated every hour without the need for interaction from a site user.

Any thoughts?
Reply With Quote

  #2 (permalink)  
Old Aug 18th, 2005, 12:05
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
The burdon is going to have to be on something! I have in the past created an .vbs file which launches internet explorer on the server and goes to a specific page, this page performs my database tasks. The vbs file is set to run everyday using Windows built-in task scheduler. I think that would be a solution for you, heres the vbs code:

Code: Select all
Set newShell = CreateObject("WScript.Shell")
newShell.run "http://my-site.com/task.asp",5,false
Hope that helps
Reply With Quote
  #3 (permalink)  
Old Aug 18th, 2005, 12:44
Junior Member
Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
ok, but my site is hosted on shared hosting space, won't this prohibit me running processes such as this? I'm afraid I'm a newby as regards vbs applications and client side scripts. My asp knowledge only stretches into its implementation on web pages as server side scripting.

I've also just discoved that I have a problem reading the .csv file on the product suppliers site using the asp fso object. I think it is something to do with permisions at their end, but I can't speak to anybody there until monday.

All a bit belly up really, but thanks.
Reply With Quote
  #4 (permalink)  
Old Aug 18th, 2005, 16:05
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
in that case the .vbs and task scheduler will have to run on your computer or a server that you have full control over.
Reply With Quote
  #5 (permalink)  
Old Aug 18th, 2005, 17:12
Junior Member
Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
hmm. right. I'll have a think.

Thanks for all your help.
Reply With Quote
  #6 (permalink)  
Old Aug 18th, 2005, 18:09
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Smokie's suggestion is the usual way this is done.
Reply With Quote
  #7 (permalink)  
Old Aug 19th, 2005, 01:09
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Let me make an alternaive suggestion....

The text file (containing out of date stock items) should be placed in a directory and queried everytime a product SELECTtion (from the database) is performed.

Now whilst that may sound pretty slow we are actually only talking about milliseconds here so the 'slow' will likely be mostly unnoticeable.

My suggestion would be to read the text document: perform the needed action to mark products out of stock in the DB and then... delete the text file.

Every time a product SELECTion is needed, just see if that file exists, if it doesnt, do nothing.... if it does, then do yer stuff.

Just a suggestion.
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
  #8 (permalink)  
Old Aug 19th, 2005, 08:11
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Doesn't windows hosting have anything similiar to Unix's cron?
Reply With Quote
  #9 (permalink)  
Old Aug 19th, 2005, 12:22
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
the closest thing to cron is the windows task scheduler and typically microsoft didnt make it web friendly on their webserver products... Some webhosts do offer asp scheduling (crystaltech) but its pretty rare AFAIK. Robs sugesstion is the cleanest.
Reply With Quote
  #10 (permalink)  
Old Aug 19th, 2005, 18:29
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Quote:
Originally Posted by Smokie
Robs sugesstion is the cleanest.
Well.... I thought so too
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
  #11 (permalink)  
Old Aug 23rd, 2005, 06:03
Reputable Member
Join Date: Sep 2004
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Hate to not be offering help... but this is VERY usefull information to me, I just stumbled across this same problem. Thanks guys
Reply With Quote
  #12 (permalink)  
Old Aug 24th, 2005, 11:40
Junior Member
Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry about the delay in replying. I've been tring to get hold of the company which holds the text file on their server.

I agree with everything you guys have said (thanks), and will run some script to update the database at those times when a SELECTion is made (as Rob suggested), rather than trying to schedule the script.

The problem at the moment is that the text file containing the info is on the suppliers server, and I haven't managed to read from it using my asp fso object. I just get a "file cannot be found" message. I gather that reading remote files often fails because of permissions on the source file. I am waiting to hear back from the technical guys at the supplier about this.

If anybody has anymore pointers about reading remote text files using the fso, or if there is a method by which I can automatically copy the remote file onto my server so that I can read it from there, I would be grateful.

Thanks again to all!
Reply With Quote
  #13 (permalink)  
Old Aug 24th, 2005, 11:49
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
i think you'll need to use Microsoft's ServerXMLHTTP component (should already be available on your server) to grab the text file, this example should get you started:

Code: Select all
<%
Dim objXmlHttp
Dim strTextFile

Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

objXmlHttp.open "GET", "http://server/text.txt", False

objXmlHttp.send

strTextFile = objXmlHttp.responseText

Response.Write(strTextfile)

Set objXmlHttp = Nothing
%>
...oh and, no you wont be able to read a remote text file using the FSO.
Reply With Quote
  #14 (permalink)  
Old Aug 24th, 2005, 12:02
Junior Member
Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
ah right...
Cheers man. I'll have a go with this.
Reply With Quote
  #15 (permalink)  
Old Aug 24th, 2005, 12:22
Junior Member
Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
wow! brilliant. This looks to be just what I need. Cheers smokie.
Reply With Quote
  #16 (permalink)  
Old Aug 24th, 2005, 14:46
Junior Member
Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks guys, all sorted now.
I've ended up with a script which sets an application variable which keeps track of when the last update was performed. The overall script is run everytime somebody queries the database, but the update based on the remote text file is only performed in my database if the application variable was set more than an hour ago. This means that I can guarantee that the database is never more than one hour out of date, but that the script isn't run more than once an hour.

Heres my final script for anybody who's interested

Code: Select all
<%
updateDifference = DateDiff("s",now(),application("lastupdate"))	
updateDifference=cint(right(updateDifference,len(updateDifference)-1))
if updateDifference>3600 then 
	
	Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP") 
	objXmlHttp.open "GET", "http://www.remoteserver.com/textfile.csv", False 
	objXmlHttp.send 
	strTextFile = objXmlHttp.responseText 

	sql= "UPDATE products SET stock='n' WHERE supplier='apollo'"
	objconn.execute(sql)

	codes = split(strTextfile, ","&chr(13)&chr(10))
	i=0
	for i = 0 to Ubound(codes)
		sql= "UPDATE products SET apollostock='y' WHERE product_id='"&codes(i)&"'"
		objconn.execute(sql)
		response.write codes(i)
	next
	application("lastupdate")=now()
	Set objXmlHttp = Nothing 
end if
%>
Reply With Quote
  #17 (permalink)  
Old Aug 24th, 2005, 15:48
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
Great job, glad it worked for ya!
Reply With Quote
Reply

Tags
scheduled, asp, script

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with this script korvix JavaScript Forum 1 May 28th, 2008 23:00
Just following the script... chrisomatix Introduce Yourself 3 Feb 27th, 2008 07:03
Js Ad Script laffin JavaScript Forum 0 Nov 28th, 2007 10:13
script help ehud36new JavaScript Forum 2 Nov 13th, 2007 13:15
Changes to CSS script Accurax Web Page Design 6 Dec 17th, 2006 16:36


All times are GMT. The time now is 04:56.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43