Methods for implementing timed tasks in ASP--application techniques

Source: Internet
Author: User

A very common ASP question: "How do I schedule a workflow to execute a Web page?", most likely because an administrator might use an ASP Web page to perform database maintenance actions, such as backups, and there is a way to do the work process on the Windows NT platform, which is at command + Schedule service, is the task of planning, but unfortunately you do not have the program in the command column (command-line) to execute ASP Web pages.

Of course you can execute IE on the command line and tell it the Web page that you want to execute, for example:
C:\Program Files\Internet Explorer\iexplore.exe Http://localhost/mypage.asp,
However, this is definitely not the way most web managers want to because this has to open the browser, spend a lot of system resources, in addition, there is a disadvantage, that is, the implementation of ASP Web pages have more than time (Timeout), if you want to perform a lot of process work, you may want to change the Timeout time , too troublesome, direct neglect.

In this article, you will be presented with a solution that uses WSH (Windows scripting Host).

Suppose you now have an ad-dial system that you want to check the ad expiration date of this work automatically every morning, that is, when an ad expires, it will change its advertising status to disable, we first look at the table adinfo fields.

Copy Code code as follows:

Adid AD Code INT
Adname Advertising name VARCHAR (64)
Validtodate AD Expiration Date DateTime
adstatus AD Status INT (0 is inactive, 1 is active)

Next look at how to use WSH, basically the same as the ASP's writing is the same addition to the ASP separator does not need to use the server., the disk extension is. vbs.

Because it is not using asp.dll, so there is no ASP object mode does not apply, so write Server.CreateObject will be an error.

Using WSH as a timing workflow:

Copy Code code as follows:

' Please do not use Server.CreateObject
Set oconn = CreateObject ("Adodb.connection")
oConn.Open yourconnstring
sSQL = "Update Adinfo set Adstatus=0" _
& "Where validtodate< = '" & Date & "'"
Oconn.execute (sSQL)
Oconn.close
Set oconn = Nothing

Save As C:\scripts\updateadstatus.vbs,
WSH has two versions, one for the window version (Wscript.exe), one for the command-line version (Cscript.exe).

In this example we will use (cscript.exe), which you can perform under the DOS command column:

Copy Code code as follows:

C:\>cscript C:\scripts\updateadstatus.vbs

Then you can go to the database to query whether the information is updated, in practical applications, it is recommended that you use this file to distinguish between different periods of work, such as I will create a batch file called Dailytask.bat to perform all the daily routine work, so that I only need to do all the daily script Put it in this batch file, and then use the at Command or SQL Server Agent to perform Dailytask.bat daily.

It is highly recommended that you use the SQL Server Agent, which is more efficient and stable than using the at Command!

Configure SQL Server Agent you can perform Enterprise Manager, and you will see this when you start.

Copy Code code as follows:

Right click Jobs, select New Job.
Select step to press New.
Specify step Name, Type Select the operating System command, and set the command to execute.
Choose Schedule to set your process.

Here is a screenshot of the database:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.