Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: update from within a loop?


Message #1 by "JD O'Riordan" <jd88@h...> on Tue, 5 Nov 2002 14:17:03
Hi.
Sorry if this isn't the right place for this message...

I iterates through the records of a small db table (a couple hundred 
records--which are file names and 'last modified' dates) and compares info 
from each record to related info from the file system. It updates the 
database from inside the loop.

I'm concerned that creating and destroying filesystemobjects -- as well as 
executing several database connection objects -- from within the loop is 
putting a big hit on the server or just isn't a very good idea.

Thanks in advance for comments.
jd

here's the code:

while not rs.eof
        record_id = rs("id")
        path = rs("path")
        filename = rs("filename")
        whichfile = path & filename

        set fso=createobject("scripting.filesystemobject")
        set file=fso.getfile(whichfile)
        vb_date = file.datelastmodified
        v_year = mid(vb_date,7,4)
        v_month = mid(vb_date,1,2)
        v_day = mid(vb_date,4,2)

        v_date = v_year & "-" & v_month & "-" & v_day

        if v_date <> rs("last_mod") then
                update_last_mod_sql = "update sometable set last_mod = '" 
& v_date & "' where id = '" & record_id & "'"
                LinkConn.Execute(update_last_mod_sql)
        end if

        if rs("today") = rs("last_mod") then
                update_recent_edits_sql = "update sometable set 
recent_edits = true where id = '" & record_id & "'"
                LinkConn.Execute(update_recent_edits_sql)
        end if

        set fso = nothing
        set file = nothing

rs.movenext
wend
Message #2 by Greg Griffiths <greg2@s...> on Tue, 05 Nov 2002 20:23:49 +0000
Why not read the data into an array, update the array and then reconnect to 
the db and update as required within a transaction.

At 14:17 05/11/02 +0000, you wrote:
>Hi.
>Sorry if this isn't the right place for this message...
>
>I iterates through the records of a small db table (a couple hundred
>records--which are file names and 'last modified' dates) and compares info
>from each record to related info from the file system. It updates the
>database from inside the loop.
>
>I'm concerned that creating and destroying filesystemobjects -- as well as
>executing several database connection objects -- from within the loop is
>putting a big hit on the server or just isn't a very good idea.
>
>Thanks in advance for comments.
>jd
>
>here's the code:
>
>while not rs.eof
>         record_id = rs("id")
>         path = rs("path")
>         filename = rs("filename")
>         whichfile = path & filename
>
>         set fso=createobject("scripting.filesystemobject")
>         set file=fso.getfile(whichfile)
>         vb_date = file.datelastmodified
>         v_year = mid(vb_date,7,4)
>         v_month = mid(vb_date,1,2)
>         v_day = mid(vb_date,4,2)
>
>         v_date = v_year & "-" & v_month & "-" & v_day
>
>         if v_date <> rs("last_mod") then
>                 update_last_mod_sql = "update sometable set last_mod = '"
>& v_date & "' where id = '" & record_id & "'"
>                 LinkConn.Execute(update_last_mod_sql)
>         end if
>
>         if rs("today") = rs("last_mod") then
>                 update_recent_edits_sql = "update sometable set
>recent_edits = true where id = '" & record_id & "'"
>                 LinkConn.Execute(update_recent_edits_sql)
>         end if
>
>         set fso = nothing
>         set file = nothing
>
>rs.movenext
>wend




  Return to Index