0

Hi there I wish to run the following code every day at 9 am. Basically, the code will read a txt file and from each line. It will process and insert into a Mysql table. How do I accomplish this? I have found the following Make server automatic run asp-script every day but it is not working. Please help.

  <%
    strFileName = "database/testdata.txt"                                        

    Set fso = Server.CreateObject("Scripting.FileSystemObject") 
    set fs = fso.OpenTextFile(Server.MapPath(strFileName), 1, true) 
    if not fs.AtEndOfStream then
        Do while not fs.AtEndOfStream 
            strRow = fs.ReadLine
            sDate = Mid(Trim(strRow), 1, 8)

            Set rstTMClk1 = server.CreateObject("ADODB.RecordSet")    '=== Transfer from file to TMCLK1
            sSQL = "select * from TMCLK1 '" 
            rstTMClk1.Open sSQL, conn, 3, 3
            if rstTMClk1.eof then '=== To avoid duplicates
                sSQL = "insert into TMCLK1 (DT_WORK) "
                sSQL = sSQL & "values ("
                sSQL = sSQL & "'" & fdate2(sDate) & "'"     
                sSQL = sSQL & ") "
                conn.execute sSQL
            end if
            pCloseTables(rstTMClk1)
        Loop
    end if
    pCloseTables(fs)
%>
Hanz Cheah
  • 761
  • 5
  • 15
  • 44
  • copy the code into a VBS file, change all references of Server.CreateObject to just CreateObject, set up your job, and you're good to go. – Josh Montgomery Nov 22 '17 at 14:47

1 Answers1

0

As per @JoshMontgomery comment, you can set this up as a vbscript job and call it from task executor. The only issue you might face is folder/file access as the scheduled job will run as some system-assigned user account like Network.

If you still want to run it as an asp page then check that it runs when called manually via URL in a browser address bar. Make sure you do this from the server on which the scheduled task will be run from.

Then move this to a scheduled task. I use wget from http://www.gnu.org/software/wget/, which is a free command line http utility - give it the URL you had in the address bar and away you go. For the scheduled task make the action wget.exe and the argument the full URL of the ASP page.

Vanquished Wombat
  • 9,075
  • 5
  • 28
  • 67