Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > Classic ASP

Reply
 
LinkBack Thread Tools
Old August 18th, 2005, 05:47 AM   #1
New Member
 

Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 simonneaves is on a distinguished road
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?
simonneaves is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 18th, 2005, 08:05 AM   #2
Highly Reputable Member
 

Join Date: Jul 2003
Location: Ipswich, UK
Posts: 686
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Smokie will become famous soon enough
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:
Set newShell = CreateObject("WScript.Shell")
newShell.run "http://my-site.com/task.asp",5,false
Hope that helps
Smokie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 18th, 2005, 08:44 AM   #3
New Member
 

Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 simonneaves is on a distinguished road
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.
simonneaves is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 18th, 2005, 12:05 PM   #4
Highly Reputable Member
 

Join Date: Jul 2003
Location: Ipswich, UK
Posts: 686
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Smokie will become famous soon enough
in that case the .vbs and task scheduler will have to run on your computer or a server that you have full control over.
Smokie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 18th, 2005, 01:12 PM   #5
New Member
 

Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 simonneaves is on a distinguished road
hmm. right. I'll have a think.

Thanks for all your help.
simonneaves is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 18th, 2005, 02:09 PM   #6
WebForumz Admin Badge
 

Join Date: Jul 2003
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 118 Webforumz Staff is on a distinguished road
Smokie's suggestion is the usual way this is done.
Webforumz Staff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 18th, 2005, 09:09 PM   #7
Rob
Elite Veteran
SuperMember
 
Rob's Avatar
 

Join Date: Jul 2003
Location: Southern UK
Age: 35
Posts: 3,126
Blog Entries: 7
Thanks: 28
Thanked 22 Times in 19 Posts
Rep Altering Power: 0 Rob is a jewel in the rough Rob is a jewel in the rough Rob is a jewel in the rough
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 - Webforumz Founder
Web Designer Support Network || Personal Project: Sanctuary for Student Midwives
Rob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 19th, 2005, 04:11 AM   #8
WebForumz Admin Badge
 

Join Date: Jul 2003
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 118 Webforumz Staff is on a distinguished road
Doesn't windows hosting have anything similiar to Unix's cron?
Webforumz Staff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 19th, 2005, 08:22 AM   #9
Highly Reputable Member
 

Join Date: Jul 2003
Location: Ipswich, UK
Posts: 686
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Smokie will become famous soon enough
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.
Smokie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 19th, 2005, 02:29 PM   #10
Rob
Elite Veteran
SuperMember
 
Rob's Avatar
 

Join Date: Jul 2003
Location: Southern UK
Age: 35
Posts: 3,126
Blog Entries: 7
Thanks: 28
Thanked 22 Times in 19 Posts
Rep Altering Power: 0 Rob is a jewel in the rough Rob is a jewel in the rough Rob is a jewel in the rough
Quote:
Originally Posted by Smokie
Robs sugesstion is the cleanest.
Well.... I thought so too
__________________
Rob - Webforumz Founder
Web Designer Support Network || Personal Project: Sanctuary for Student Midwives
Rob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 23rd, 2005, 02:03 AM   #11
Reputable Member
 

Join Date: Sep 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 JohnMitch is on a distinguished road
Hate to not be offering help... but this is VERY usefull information to me, I just stumbled across this same problem. Thanks guys
JohnMitch is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 24th, 2005, 07:40 AM   #12
New Member
 

Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 simonneaves is on a distinguished road
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!
simonneaves is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 24th, 2005, 07:49 AM   #13
Highly Reputable Member
 

Join Date: Jul 2003
Location: Ipswich, UK
Posts: 686
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Smokie will become famous soon enough
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:
<%
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.
Smokie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 24th, 2005, 08:02 AM   #14
New Member
 

Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 simonneaves is on a distinguished road
ah right...
Cheers man. I'll have a go with this.
simonneaves is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 24th, 2005, 08:22 AM   #15
New Member
 

Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 simonneaves is on a distinguished road
wow! brilliant. This looks to be just what I need. Cheers smokie.
simonneaves is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 24th, 2005, 10:46 AM   #16
New Member
 

Join Date: May 2005
Location: bath - england
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 simonneaves is on a distinguished road
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:
<%
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
%>
simonneaves is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 24th, 2005, 11:48 AM   #17
Highly Reputable Member
 

Join Date: Jul 2003
Location: Ipswich, UK
Posts: 686
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Smokie will become famous soon enough
Great job, glad it worked for ya!
Smokie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
scheduled , asp , script


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 1 May 28th, 2008 07:00 PM
Js Ad Script laffin JavaScript 0 November 28th, 2007 06:13 AM
script help ehud36new JavaScript 2 November 13th, 2007 09:15 AM
Changes to CSS script Accurax HTML, XHTML and CSS 6 December 17th, 2006 12:36 PM


Search Engine Optimization by vBSEO 3.2.0 RC8