我正在尝试通过Windows任务计划程序触发的vbs文件执行ASP页面。
任务正在完成且没有错误,但是它立即完成并且没有更新我的数据库。如果我直接通过浏览器运行ASP,它确实可以正常工作。想法?
VBS文件代码:
Dim url, xmlhttp
url = "http://localhost/adr-gateway/index-sysmon-cdDB.asp" ' ASP script to run
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
set xmlhttp = nothing
ASP文件代码:基本上从1个数据库中提取数据并将其插入另一个数据库。
<%
'===================================================================================================================
'GET TOTAL NUMBER OF COMPLETED IMPORTS IN LAST HOUR
'===================================================================================================================
'MY SQL - DEFINE CONNECTION STRING & SPECIFY DB DRIVER
ConnString = "DRIVER={MySQL ODBC 5.3 ANSI Driver}; SERVER=174.xx.xx.xxx; DATABASE=content_distributor; " &_
"UID=admin;PASSWORD=admin; PORT=3306 ; OPTION=3"
'CREATE INSTANCE OF ADO CONNECTION AND RECORDSET OBJECTS
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'OPEN CONNECTION TO DB
Connection.Open ConnString
'SQL STATEMENT TO QUERY DB
SQL = "SELECT * FROM jobs WHERE DATE_ADD(updated_at, INTERVAL 60 MINUTE) > NOW() AND job_type='IMPORT' AND state='COMPLETE'"
'OPEN RECORDSET AND RETURN SQL QUERY
Recordset.Open SQL,Connection
'CHECK FOR RECORDS
If Recordset.EOF Then
msg = "No Records Present in Database"
Else
'SET COUNT VARIABLE
importCount = 0
'IF THERE ARE RECORDS LOOP THROUGH THE DB
Do While NOT Recordset.Eof
importCount = importCount + 1
Recordset.MoveNext
Loop
End If
'CLOSE CONNECTION AND RECORDSET TO FREE UP CONNECTIONS
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
'===================================================================================================================
'GET TOTAL NUMBER OF COMPLETED COPY JOBS IN LAST HOUR
'===================================================================================================================
'MY SQL - DEFINE CONNECTION STRING & SPECIFY DB DRIVER
ConnString = "DRIVER={MySQL ODBC 5.3 ANSI Driver}; SERVER=174.75.78.150; DATABASE=content_distributor; " &_
"UID=admin;PASSWORD=admin; PORT=3306 ; OPTION=3"
'CREATE INSTANCE OF ADO CONNECTION AND RECORDSET OBJECTS
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'OPEN CONNECTION TO DB
Connection.Open ConnString
'SQL STATEMENT TO QUERY DB
SQL = "SELECT * FROM jobs WHERE DATE_ADD(updated_at, INTERVAL 60 MINUTE) > NOW() AND job_type='COPY' AND state='COMPLETE'"
'OPEN RECORDSET AND RETURN SQL QUERY
Recordset.Open SQL,Connection
'CHECK FOR RECORDS
If Recordset.EOF Then
msg = "No Records Present in Database"
Else
'SET COUNT VARIABLE
copyCount = 0
'IF THERE ARE RECORDS LOOP THROUGH THE DB
Do While NOT Recordset.Eof
copyCount = copyCount + 1
Recordset.MoveNext
Loop
End If
'CLOSE CONNECTION AND RECORDSET TO FREE UP CONNECTIONS
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
'===================================================================================================================
'GET TOTAL NUMBER OF COMPLETED DELETE JOBS IN LAST HOUR
'===================================================================================================================
'MY SQL - DEFINE CONNECTION STRING & SPECIFY DB DRIVER
ConnString = "DRIVER={MySQL ODBC 5.3 ANSI Driver}; SERVER=174.75.78.150; DATABASE=content_distributor; " &_
"UID=admin;PASSWORD=admin; PORT=3306 ; OPTION=3"
'CREATE INSTANCE OF ADO CONNECTION AND RECORDSET OBJECTS
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'OPEN CONNECTION TO DB
Connection.Open ConnString
'SQL STATEMENT TO QUERY DB
SQL = "SELECT * FROM jobs WHERE DATE_ADD(updated_at, INTERVAL 60 MINUTE) > NOW() AND job_type='DELETEALL' AND state='COMPLETE'"
'OPEN RECORDSET AND RETURN SQL QUERY
Recordset.Open SQL,Connection
'CHECK FOR RECORDS
If Recordset.EOF Then
msg = "No Records Present in Database"
Else
'SET COUNT VARIABLE
deleteCount = 0
'IF THERE ARE RECORDS LOOP THROUGH THE DB
Do While NOT Recordset.Eof
deleteCount = deleteCount + 1
Recordset.MoveNext
Loop
End If
'CLOSE CONNECTION AND RECORDSET TO FREE UP CONNECTIONS
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
'===================================================================================================================
'GET TOTAL NUMBER OF FAILED JOBS IN LAST HOUR
'===================================================================================================================
'MY SQL - DEFINE CONNECTION STRING & SPECIFY DB DRIVER
ConnString = "DRIVER={MySQL ODBC 5.3 ANSI Driver}; SERVER=174.75.78.150; DATABASE=content_distributor; " &_
"UID=admin;PASSWORD=admin; PORT=3306 ; OPTION=3"
'CREATE INSTANCE OF ADO CONNECTION AND RECORDSET OBJECTS
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'OPEN CONNECTION TO DB
Connection.Open ConnString
'SQL STATEMENT TO QUERY DB
SQL = "SELECT * FROM jobs WHERE DATE_ADD(updated_at, INTERVAL 60 MINUTE) > NOW() AND state='FAILED'"
'OPEN RECORDSET AND RETURN SQL QUERY
Recordset.Open SQL,Connection
'CHECK FOR RECORDS
If Recordset.EOF Then
msg = "No Records Present in Database"
failedCount = "0"
Else
'SET COUNT VARIABLE
failedCount = 0
'IF THERE ARE RECORDS LOOP THROUGH THE DB
Do While NOT Recordset.Eof
failedCount = failedCount + 1
Recordset.MoveNext
Loop
End If
'CLOSE CONNECTION AND RECORDSET TO FREE UP CONNECTIONS
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("DB/TS-GATEWAY.mdb")
'Create an ADO recordset object
Set rsAdd = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM CD_Health;"
'Set the cursor type we are using so we can navigate through the recordset
rsAdd.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rsAdd.LockType = 3
'Open the recordset with the SQL query
rsAdd.Open strSQL, adoCon
'Tell the recordset we are adding a new record to it
rsAdd.AddNew
'Add a new record to the recordset
rsAdd.Fields("importCount") = importCount
rsAdd.Fields("copyCount") = copyCount
rsAdd.Fields("deleteCount") = deleteCount
rsAdd.Fields("failedCount") = failedCount
'Write the updated recordset to the database
rsAdd.Update
'Reset server objects
rsAdd.Close
Set rsAdd = Nothing
Set adoCon = Nothing
%>