|
 |
asp_web_howto thread: Scheduled Task on Windows.
Message #1 by kayandipo@h... on Thu, 20 Sep 2001 11:13:34
|
|
Dear All,
Below is my script which reads a text file and saves it onto the DB, what
I want know is to make it a .VBS file which runs at a prescheduled time, I
know I have to change my server.createobject to wscript.createobject, what
other CODE do I need for this to run when scheduled.
I look forward to all coding help, Thanks.
<%@ Language = VBScript %>
<HTML>
<!--#include file=odbc2.inc-->
<%
const constForReading = 1
const constTristateFalse = 0
Dim fsObject
dim tsObject
dim strreturned
set fsObject = server.CreateObject("Scripting.FileSystemObject")
set tsObject = fsObject.OpenTextFile
("C:\INETPUB\WWWROOT\HONGKONG\HKT2.txt",1,0)
Do while not tsobject.AtEndOfLine
strReturned = tsobject.readLine
fieldno = split(strReturned,"|")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ODBCdsn,ODBCusr,ODBCpwd
Set RS1 = Server.CreateObject("ADODB.Recordset")
Set RS2 = Server.CreateObject("ADODB.Recordset")
Set RS3 = Server.CreateObject("ADODB.Recordset")
Q1 = "UPDATE HK_details SET Desp_no = '"& fieldno(3) &"', Inv_no = '"&
fieldno(4) &"', Desp_date = '"& fieldno(0) &"' where order_id = '"& fieldno
(1)&"'"
RS1.Open Q1,Conn
Q2 = "INSERT INTO PK_despatch(Order_id,courier_code,courier_tracking_no )
VALUES ('"& fieldno(1)&"','"& fieldno(6) &"','"& fieldno(5) &"')"
RS2.Open Q2,Conn
Q3 = "UPDATE TK_headers SET KUP_Order_id = '"& fieldno(2) &"' where
Order_id = '"& fieldno(1) &"'"
RS3.Open Q3,Conn
Response.Write RS1.Source&"<BR>"
Response.Write RS2.Source&"<BR>"
Response.Write RS3.Source&"<BR>"
loop
'RS1.Close
'RS2.Close
'RS3.Close
set RS1 = nothing
set RS2 = nothing
set RS3 = nothing
set Conn = nothing
%>
</HTML>
Message #2 by Sam Clohesy <sam@e...> on Thu, 20 Sep 2001 11:30:11 +0100
|
|
Hi,
I have just done something fairly similar and I found that I could'nt run
include files and that you can get away with just createobject.
With regards to scheduling you can check it is working by double clicking on
it in explorer then if you are running 2000 go to control panel and
scheduled tasks altenatively do it in the command prompt with something
like:
Start >> Run... >> cmd >> at 2:00 /every:s,m,t,w,th,f <root for
3sectorsjob>\emailer\index.vbs
for example
at 2:00 /every:s,m,t,w,th,f d:\inetpub\wwwroot\3sectorsjob\emailer\index.vbs
Hope this useful and apologies if it overly long
Thanks
Sam
-----Original Message-----
From: kayandipo@h... [mailto:kayandipo@h...]
Sent: 20 September 2001 12:14
To: ASP Web HowTo
Subject: [asp_web_howto] Scheduled Task on Windows.
Dear All,
Below is my script which reads a text file and saves it onto the DB, what
I want know is to make it a .VBS file which runs at a prescheduled time, I
know I have to change my server.createobject to wscript.createobject, what
other CODE do I need for this to run when scheduled.
I look forward to all coding help, Thanks.
<%@ Language = VBScript %>
<HTML>
<!--#include file=odbc2.inc-->
<%
const constForReading = 1
const constTristateFalse = 0
Dim fsObject
dim tsObject
dim strreturned
set fsObject = server.CreateObject("Scripting.FileSystemObject")
set tsObject = fsObject.OpenTextFile
("C:\INETPUB\WWWROOT\HONGKONG\HKT2.txt",1,0)
Do while not tsobject.AtEndOfLine
strReturned = tsobject.readLine
fieldno = split(strReturned,"|")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ODBCdsn,ODBCusr,ODBCpwd
Set RS1 = Server.CreateObject("ADODB.Recordset")
Set RS2 = Server.CreateObject("ADODB.Recordset")
Set RS3 = Server.CreateObject("ADODB.Recordset")
Q1 = "UPDATE HK_details SET Desp_no = '"& fieldno(3) &"', Inv_no = '"&
fieldno(4) &"', Desp_date = '"& fieldno(0) &"' where order_id = '"& fieldno
(1)&"'"
RS1.Open Q1,Conn
Q2 = "INSERT INTO PK_despatch(Order_id,courier_code,courier_tracking_no )
VALUES ('"& fieldno(1)&"','"& fieldno(6) &"','"& fieldno(5) &"')"
RS2.Open Q2,Conn
Q3 = "UPDATE TK_headers SET KUP_Order_id = '"& fieldno(2) &"' where
Order_id = '"& fieldno(1) &"'"
RS3.Open Q3,Conn
Response.Write RS1.Source&"<BR>"
Response.Write RS2.Source&"<BR>"
Response.Write RS3.Source&"<BR>"
loop
'RS1.Close
'RS2.Close
'RS3.Close
set RS1 = nothing
set RS2 = nothing
set RS3 = nothing
set Conn = nothing
%>
</HTML>
Message #3 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Thu, 20 Sep 2001 11:53:43 +0100
|
|
CreateObject() is fine. You can't do includes, you will need to cut and
paste the code in. A script file only contains code, so get rid of any
HTML, and also there is no need for context-switching tags (<%%>), as there
is only one context. Remove the language declaration, the vbs extension
tells the parser that its vbscript. Also remove any references to the ASP
object model (Request,Response,Server,Session,Application)
-----Original Message-----
From: kayandipo@h... [mailto:kayandipo@h...]
Sent: 20 September 2001 12:14
To: ASP Web HowTo
Subject: [asp_web_howto] Scheduled Task on Windows.
Dear All,
Below is my script which reads a text file and saves it onto the DB, what
I want know is to make it a .VBS file which runs at a prescheduled time, I
know I have to change my server.createobject to wscript.createobject, what
other CODE do I need for this to run when scheduled.
I look forward to all coding help, Thanks.
<%@ Language = VBScript %>
<HTML>
<!--#include file=odbc2.inc-->
<%
const constForReading = 1
const constTristateFalse = 0
Dim fsObject
dim tsObject
dim strreturned
set fsObject = server.CreateObject("Scripting.FileSystemObject")
set tsObject = fsObject.OpenTextFile
("C:\INETPUB\WWWROOT\HONGKONG\HKT2.txt",1,0)
Do while not tsobject.AtEndOfLine
strReturned = tsobject.readLine
fieldno = split(strReturned,"|")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ODBCdsn,ODBCusr,ODBCpwd
Set RS1 = Server.CreateObject("ADODB.Recordset")
Set RS2 = Server.CreateObject("ADODB.Recordset")
Set RS3 = Server.CreateObject("ADODB.Recordset")
Q1 = "UPDATE HK_details SET Desp_no = '"& fieldno(3) &"', Inv_no = '"&
fieldno(4) &"', Desp_date = '"& fieldno(0) &"' where order_id = '"& fieldno
(1)&"'"
RS1.Open Q1,Conn
Q2 = "INSERT INTO PK_despatch(Order_id,courier_code,courier_tracking_no )
VALUES ('"& fieldno(1)&"','"& fieldno(6) &"','"& fieldno(5) &"')"
RS2.Open Q2,Conn
Q3 = "UPDATE TK_headers SET KUP_Order_id = '"& fieldno(2) &"' where
Order_id = '"& fieldno(1) &"'"
RS3.Open Q3,Conn
Response.Write RS1.Source&"<BR>"
Response.Write RS2.Source&"<BR>"
Response.Write RS3.Source&"<BR>"
loop
'RS1.Close
'RS2.Close
'RS3.Close
set RS1 = nothing
set RS2 = nothing
set RS3 = nothing
set Conn = nothing
%>
</HTML>
Message #4 by kayandipo@h... on Thu, 20 Sep 2001 15:19:22
|
|
Thank you for your helps above I have changed the script as suggested
below but cant get the scheduler to do the job,
I had the following error message when I used the "scheduled task" in Win2k
"The new task has been created, but may not run because the account
information could not be set. The specific error is: Unable to establish
existence of the account specified."
the "AT" command also showed the scheduler to have been set up.
Any further help would be appreciated.
ODBCdsn="devDSN"
ODBCusr="devUser"
ODBCpwd="goingon"
const constForReading = 1
const constTristateFalse = 0
Dim fsObject
dim tsObject
dim strreturned
set fsObject = wscript.CreateObject("Scripting.FileSystemObject")
set tsObject = fsObject.OpenTextFile
("C:\INETPUB\WWWROOT\HONGKONG\HKT2.txt",1,0)
Do while not tsobject.AtEndOfLine
strReturned = tsobject.readLine
fieldno = split(strReturned,"|")
Set Conn = wscript.CreateObject("ADODB.Connection")
Conn.Open ODBCdsn,ODBCusr,ODBCpwd
Set RS1 = wsript.CreateObject("ADODB.Recordset")
Set RS2 = wscript.CreateObject("ADODB.Recordset")
Set RS3 = wscript.CreateObject("ADODB.Recordset")
Q1 = "UPDATE PK_details SET Desp_no = '"& fieldno(3) &"', Inv_no = '"&
fieldno(4) &"', Desp_date = '"& fieldno(0) &"' where order_id = '"& fieldno
(1)&"'"
RS1.Open Q1,Conn
Q2 = "INSERT INTO HK_despatch(Order_id,courier_code,courier_tracking_no )
VALUES ('"& fieldno(1)&"','"& fieldno(6) &"','"& fieldno(5) &"')"
RS2.Open Q2,Conn
Q3 = "UPDATE TK_headers SET ERP_Order_id = '"& fieldno(2) &"' where
Order_id = '"& fieldno(1) &"'"
RS3.Open Q3,Conn
loop
'RS1.Close
'RS2.Close
'RS3.Close
set RS1 = nothing
set RS2 = nothing
set RS3 = nothing
set Conn = nothing
|
|
 |