It is a common function to execute tasks regularly in the system. So do you know how to implement timing tasks in ASP? The editor of the Error New Technology Channel recommends that you come to js.VeVb.com to learn.
A very common ASP question: "How to execute web pages on a timed workflow?" Most of the reason why this question is asked is that administrators may use an ASP web page to perform database maintenance actions, such as backup. On the Windows NT platform, there is a way to do workflow, that is, AT command + Schedule service, which is to plan tasks. Unfortunately, you do not have the rules to execute ASP web pages on the command-Line.
Of course you can execute IE in the command column and tell it the web page that requires execution, for example:
c:/program files/internet explorer/iexplore.exe http://localhost/mypage.asp,
However, this is definitely not the method that most website managers need, because it requires opening the browser and spending a lot of system resources. In addition, there is a disadvantage, that is, there is a timeout time (Timeout) for executing ASP web pages. If you want to perform a lot of process work, you may have to change the timeout time. It is too troublesome and you will ignore it directly.
In this article, we will introduce a solution using WSH (Windows Scripting Host).
Suppose you now have an ad dial system, and you want to automate the checking of the ad expiration date. This work is performed every morning, that is, when an ad expires, it will change its ad status to deactivate. Let's first look at the AdInfo field of the information table.
The code copy is as follows:AdId Ad Code INT
AdName Advertising nameVARCHAR(64)
ValidToDate Ad Expiry DateDateDate
AdStatus Ad Status INT (0 is deactivated, 1 is carried out)
Next, let’s take a look at how to use WSH. Basically, the writing method is the same as ASP except that you do not need to add an ASP delimiter and cannot use Server. The storage extension is .vbs.
Since asp.dll is not used, object mode without ASP is not applicable, so writing Server.CreateObject in this way will cause an error.
Use WSH to make a timed workflow:
The code copy is as follows:'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,
There are two versions of WSH, one is the window version (wscript.exe) and the other is the command version (cscript.exe).
In this example we will use (cscript.exe), you can execute it under the DOS command column:
The code copy is as follows:c:/scripts/updateadstatus.vbs
Then you can go to the database to query whether the data is updated. In actual applications, it is recommended that you use batch files to distinguish work in different periods. For example, I will create a batch file called dailytask.bat to perform all the daily routine work. In this way, I just need to put all scripts that should be executed every day into this batch file, and then use AT Command or SQL Server Agent to execute dailytask.bat regularly.
It is highly recommended to use SQL Server Agent, which is more efficient and stable than using AT Command!
Setting up SQL Server Agent You can execute Enterprise Manager, and you will see this screen after expanding.
The code copy is as follows:Click Jobs on the right mouse button and select New Job.
Select Step Press New.
Specify Step Name and Type Please select Operating System Command and set the executed Command.
Select Schedule to set your process.
Here is a screenshot of the database:
The above is the method of implementing timed tasks in ASP introduced by the editor of the Error New Technology Channel. I hope it can help everyone learn. If you want to know more about it, please go to js.VeVb.com for consultation.