asp 我想每隔5分钟就执行 一次下面的代码 setInterval(aaa,1000*60*5)不知道这个怎么写呀,

<%
set rs_del=server.createobject("adodb.recordset")
set rs_ins=server.createobject("adodb.recordset")
set rs_w_del=server.createobject("adodb.recordset")
set rs_w_ins=server.createobject("adodb.recordset")
sql_del="delete from temp_1"
sql_ins="insert into temp_1(machineid,machinename,platebegin,plateend,sectionnumber,modulecode,platetime ) select a.machineid,a.machinename,b.platebegin,b.plateend,c.sectionnumber,e.modulecode,b.platetime from machine a,detailsection b,OrderDetail c ,producemanage d,operation e where a.machineid = b.machineid and b.orderdetailid= c.orderdetailid and c.producemanageid=d.producemanageid and d.operationid=e.operationid and c.closed=0 and e.modulecode<>'' and b.platebegin IS NOT NULL "
sql_w_del="delete from tmp_sql"

sql_w_ins="insert into tmp_sql select a.machineid,a.machinename,b.platebegin,b.plateend,b.sectionnumber,b.modulecode,e.deptname,e.deptid,a.remark,b.platetime from machine a,temp_1 b,workstep c,SetActualizeStepDisplay d,dept e where a.machineid *= b.machineid and a.workstepid = c.workstepid and c.workstepid = d.workstepid and d.deptid = e.deptid and e.deptid=20 and exists(select 1 from (select machineid,maxplatebegin = max(platebegin) from temp_1 group by machineid ) f where machineid = f.machineid and platebegin = f.maxplatebegin ) order by 2"

rs_del.open sql_del,connp,1,1
'rs_del.close
set rs_del=nothing

rs_w_del.open sql_w_del,connp,1,1
'rs_del.close
set rs_w_del=nothing

rs_ins.open sql_ins,connp,1,1

'rs_ins.close
set rs_ins=nothing

rs_w_ins.open sql_w_ins,connp,1,1
'rs_ins.close
set rs_w_ins=nothing
%>

用SQL的作业来实现很简单:

1、先创建存储过程:

CREATE PROCEDURE dbo.Usp_AutoExec
AS
BEGIN
SET NOCOUNT ON;
Set Transaction Isolation level repeatable Read 
begin tran

truncate table temp_1;
delete from temp_1;
insert into temp_1(machineid,machinename,platebegin,plateend,sectionnumber,modulecode,platetime )  select    a.machineid,a.machinename,b.platebegin,b.plateend,c.sectionnumber,e.modulecode,b.platetime   from machine a,detailsection b,OrderDetail c ,producemanage d,operation e  where a.machineid = b.machineid and  b.orderdetailid= c.orderdetailid and c.producemanageid=d.producemanageid  and   d.operationid=e.operationid and c.closed=0 and e.modulecode<>''  and  b.platebegin IS NOT NULL;
if @@error<>0
begin
ROLLBACK TRANSACTION;
raiserror 50001 '执行插入temp_1时出错'
end
truncate table tmp_sql;
delete from tmp_sql;
insert into tmp_sql select a.machineid,a.machinename,b.platebegin,b.plateend,b.sectionnumber,b.modulecode,e.deptname,e.deptid,a.remark,b.platetime  from  machine a,temp_1 b,workstep c,SetActualizeStepDisplay d,dept e   where a.machineid *=  b.machineid and a.workstepid = c.workstepid and  c.workstepid = d.workstepid and d.deptid = e.deptid and  e.deptid=20 and exists(select 1 from (select machineid,maxplatebegin = max(platebegin) from temp_1 group by machineid ) f where machineid = f.machineid and  platebegin = f.maxplatebegin ) order by 2;
if @@error<>0
begin
ROLLBACK TRANSACTION;
raiserror 50001 '执行插入tmp_sql时出错'
end
COMMIT TRAN
END
GO

2、创建SQL作业

http://jingyan.baidu.com/article/49ad8bce7287315834d8fab4.html

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-08-27
只要每隔5分钟刷新一下页面即可。
可以用

<meta http-equiv="refresh" content="300">
也可以用
<script>setTimeout("window.location.reload();",300000);</script>

补充说明:像这样的需求,你只能寻求html或前端js脚本去解决,而不可能用后台asp代码来解决,因为服务器端程序不可能这样长时间循环运行的,浏览器早就判定页面超时了。追问

如果刷新页面,整个程序都会从头开始了,我只是想把上面的代码执行,能不能用回圈呀,

追答

你可以把你这段代码单独保存为一个asp文件,再加上我上面所说的代码(注意必须放在的外面),然后在当前页面利用一个iframe来调用它(根据需要可以把iframe设为隐藏的),这样它就会自动每隔5分钟运行一次了。
也可以利用xmlhttp来定时调用它(这时候就不用加上我的代码了)。
如果你不懂或者不想写程序代码,建议用第一种方法,如果熟悉JavaScript和ajax,可以用第二种方法。