Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Executing .ASPX file automatically??

Author  Topic 

modest
Starting Member

32 Posts

Posted - 2006-10-31 : 19:55:59
Hi all,

I have a .aspx file wirtten in C# that does some db related task after getting some information from another url. The file is completely independent of any other .aspx file. now I would like this file to execute itself everyday, say, at 2:00am. How can I do that?


Thanks

Sitka
Aged Yak Warrior

571 Posts

Posted - 2006-11-01 : 23:27:52
you could use a WSH in Scheduled task from an always on machine

the psuedo code would look like this.

Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run """C:\Program Files\Internet Explorer\IExplore.exe""http://www.intranet.com/yourfile.aspx"
WScript.Sleep 2000
Set IEXPL = getobject("IExplore.application")
IEXPL.Quit()
WScript.Quit()

In pseudo English...
open a command prompt
Run Internet Explorer with a switch that calls the page
Wait a little while (Sleep) until the page is done
get an object that represents the running Internet Explorer
quit that object
then quit the cmd prompt


Once you construct real working code after looking in the WSH documentation for guidence schedule the resulting .vbs file with Windows task scheduler

"it's definitely useless and maybe harmful".
Go to Top of Page

modest
Starting Member

32 Posts

Posted - 2006-11-02 : 00:11:19
Thanks for the reply!

Well if it is 'useless' and 'harmful' what is the next best alternative? I am sure the question that I have posted is very common and lots of developer would want to do something like that, for example, when you have to show the latest prices of some products from amazon.com or something like that.

Can anyone suggest any other solution?

Thanks once again.
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2006-11-02 : 08:32:55
maybe try this instead to close Internet Explorer
taskkill /IM iexplore.exe

Anyways the idea is there, WSH is a big topic and there are millions of examples out there,
it also depends on the machine you run it from.

I did the syntax here


Dim oShell
Set oShell = WScript.CreateObject("WScript.shell")
oShell.run """C:\Program Files\Internet Explorer\IEXPLORE.EXE"" http://www.google.com/"
WScript.Sleep 8000
oShell.run "C:\WINDOWS\SYSTEM32\taskkill.exe /im iexplore.exe"

Set oShell = Nothing


also from the command prompt
Cscript /?

note option //H:CScript in general I've found this option works better most cases but it is machine wide setting so be careful. That warning applies to basically any WSH code, it maybe harmful



"it's definitely useless and maybe harmful".
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2006-11-02 : 09:35:58
quote:
Originally posted by modest

Thanks for the reply!

Well if it is 'useless' and 'harmful' what is the next best alternative?


Thats his signature it is on every post.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-11-02 : 09:54:54
quote:
Originally posted by modest

Hi all,

I have a .aspx file wirtten in C# that does some db related task after getting some information from another url. The file is completely independent of any other .aspx file. now I would like this file to execute itself everyday, say, at 2:00am. How can I do that?


Thanks



Sounds like you are using the wrong tool for the job. If you need something execute on a schedule and do something, you don't want a web page, you want an application.

Wouldn't it be easier just to write a quick C# app that does what you need and then use ScheduledTasks to schedule it to run when needed?

It doesn't make much sense to automate "going to a web page" which then triggers some code, especially when you are the one writing the code on the web page. Just write a simple app that does what you need and then schedule it.

- Jeff
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2006-11-02 : 11:27:05
on the road to good health, I agree with the Dr.

consider the WSH solution the pack of cigs and a fifth of burbon



"it's definitely useless and maybe harmful".
Go to Top of Page

modest
Starting Member

32 Posts

Posted - 2006-11-03 : 18:21:05
quote:

Sounds like you are using the wrong tool for the job. If you need something execute on a schedule and do something, you don't want a web page, you want an application.

Wouldn't it be easier just to write a quick C# app that does what you need and then use ScheduledTasks to schedule it to run when needed?

It doesn't make much sense to automate "going to a web page" which then triggers some code, especially when you are the one writing the code on the web page. Just write a simple app that does what you need and then schedule it.

- Jeff



hi jeff,

I think I got your point. This leads me to ask a further question. I am not sure how to database programming in C# alone. I mean all this while I have been writing the code in C# but for the webpages. Is there any huge difference in the syntax? Can we do all the things that we do in .aspx file with a standalone C# application (of course except displaying the pages)?

Thanks
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-11-03 : 19:43:09
C# is C# regardless of platform, the only differences between a web page and a regular app are the library references. You simply don't include any System.Web references. If you intend to schedule it, you'll want a console application and would therefore also eliminate all UI references. Visual Studio has a template for console applications, simply start a new project with that template and go from there. There are plenty of tutorials on the web.
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2006-11-03 : 19:46:34
You mentioned


latest prices of some products from amazon.com or something like that.


are you web scraping?

"it's definitely useless and maybe harmful".
Go to Top of Page

modest
Starting Member

32 Posts

Posted - 2006-11-03 : 20:02:27
quote:
Originally posted by Sitka

You mentioned


latest prices of some products from amazon.com or something like that.


are you web scraping?

"it's definitely useless and maybe harmful".



Well, I just tried to give an example..I never said that I am doing something like that..it's not even close..Sorry if I gave such kind of impressions.
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-11-04 : 16:37:13
In Visual Studio 2003/2005 with .NET it is now pretty simple to create a Windows Service that you can then run in the background on the server without any user interaction.

If you want it to be part of your web app you'll need to create a scheduling thread pool - there is a really nice implementation in DotNetNuke, which is open source so I think you can take the code from there, see http://dotnetnuke.com. There's a full document on their scheduler in the About/Documentation/Project Documents - here's a link, if it doesn't work, just go to the site to get it
http://www.dotnetnuke.com/LinkClick.aspx?fileticket=Sa3oPZCNyw0%3d&tabid=478&mid=857
Go to Top of Page
   

- Advertisement -