Results 1 to 5 of 5

Thread: Error in update please help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Location
    world
    Posts
    19

    Error in update please help

    Hi I have this problem.
    I added counter to my home page to count visits it was working normally but when i get more traffic i face some error there assume i have the visit counter shows 700 visit when the error appear it changes the visit counter to 0 and start from there please could any body help m with this.
    here is the code i am using
    to read old value
    VB Code:
    1. accessdb = server.mappath("any.mdb")
    2. strconn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
    3. strconn = strconn & accessDB & ";"
    4. Set conn = Server.CreateObject("ADODB.Connection")
    5. conn.open strconn
    6. strsql = "SELECT * FROM table where id=" & id
    7. Set rs = conn.execute(strsql)
    8. hits=rs("hits")
    9. rs.close
    10. set rs = nothing
    11. conn.close
    12. Set conn = nothing
    13. hits=hits+1

    update with new value

    VB Code:
    1. accessdb = server.mappath("any.mdb")
    2. strconn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
    3. strconn = strconn & accessDB & ";"
    4. Set conn = Server.CreateObject("ADODB.Connection")
    5. conn.open strconn
    6. conn.execute("update table set [hits]=" & hits & " where [id]=" & id)
    7.  conn.close
    8. Set conn = nothing

    Thanks

  2. #2
    Addicted Member techwizz's Avatar
    Join Date
    Apr 2005
    Location
    U.S.A.
    Posts
    246

    Re: Error in update please help

    you are using an access database?

    Make sure you reset objects.
    VB Code:
    1. 'Reset server objects
    2. rsWeb_Data.Close
    3. Set rsWeb_Data = Nothing
    4. Set adoCon = Nothing



    also make sure that that under tools.. options.... advanced tab that

    default level locking is set to no lock
    open database using level locking is unchecked.
    default open mode is shared.

  3. #3
    Addicted Member techwizz's Avatar
    Join Date
    Apr 2005
    Location
    U.S.A.
    Posts
    246

    Re: Error in update please help

    here is some .asp code that keeps the hits in memory

    VB Code:
    1. <div align="left">
    2. <script language="JavaScript">
    3.  
    4. Now = new Date();
    5. localtime = Now.toString();
    6. Hours = Now.getHours();
    7. if (Hours < 12) {
    8.     document.write("Good Morning...");
    9. } else {
    10.     if (Hours >= 12 && Hours < 17)  {
    11.             document.write("Good Afternoon...");
    12.     } else {
    13.         if (Hours >= 17) {
    14.             document.write("Good Evening...");
    15.             } else {
    16.             document.write("Good Day...");
    17.         }
    18.     }
    19. }
    20. </script><br>
    21.  
    22. <%
    23. ' Declare our vaiables
    24. Dim objFSO, objCountFile  ' object vars for FSO and File
    25. Dim strCountFileName      ' filename of count text file
    26. Dim iCount                ' count variable
    27. Dim bUseImages            ' boolean whether or not to use images
    28. Dim I                     ' standard looping var
    29.  
    30.  
    31. ' Determine whether we use images or plain text
    32. ' You could just set this to True or False instead
    33. bUseImages = CBool(Request.QueryString("images"))
    34.  
    35. ' Compute our count file's filename
    36. ' This is based on the file from which you call count.asp
    37. ' It basically takes that name and appends a .cnt so I don't
    38. ' accidently overwrite any files.  If for some reason you have
    39. ' a file named script_name.asp.cnt then change this or watch out!
    40. strCountFileName = Server.MapPath(Request.ServerVariables("SCRIPT_NAME") & ".cnt")
    41.  
    42.  
    43. ' Create FileSystemObject to deal with file access
    44. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    45.  
    46. ' Open the file as a text stream (1 = ForReading, True = Create)
    47. Set objCountFile = objFSO.OpenTextFile(strCountFileName, 1, True)
    48.  
    49. ' Read the current count from the file
    50. If Not objCountFile.AtEndOfStream Then
    51.     ' Set value to contents of the file
    52.     iCount = CLng(objCountFile.ReadAll)
    53. Else
    54.     ' If no file exists or it's empty start at old number
    55.     iCount = 450000
    56. End If
    57.  
    58. ' Close the file and destroy the object
    59. objCountFile.Close
    60. Set objCountFile = Nothing
    61.  
    62.  
    63. ' Increment the count
    64. iCount = iCount + 1
    65.  
    66.  
    67. ' Overwrite existing file and get a text stream to new one
    68. Set objCountFile = objFSO.CreateTextFile(strCountFileName, True)
    69.  
    70. ' Write updated count
    71. objCountFile.Write iCount
    72.  
    73. ' Close the file and destroy the object
    74. objCountFile.Close
    75. Set objCountFile = Nothing
    76.  
    77.  
    78. ' Destroy the FSO object
    79. Set objFSO = Nothing
    80.  
    81.  
    82. ' We're all done with the hard part
    83. ' All that's left is to display the results
    84. If bUseImages Then
    85.     ' Loop through the count integer showing each digit
    86.     ' You can grab the images one at a time or get the zip
    87.     ' [url]http://www.asp101.com/samples/download/counter_imgs.zip[/url]
    88.     For I = 1 to Len(iCount)
    89.         ' Output the IMG tag using the right digit
    90.         Response.Write "<img src=""./images/digit_"
    91.         Response.Write Mid(iCount, I, 1)
    92.         Response.Write ".gif"" alt="""
    93.         Response.Write Mid(iCount, I, 1)
    94.         Response.Write """ width=""20"" height=""27"" />"
    95.     Next 'I
    96. Else
    97.     ' No image wanted just show the variable
    98. %>
    99.  
    100.   You are visitor number
    101.   <%
    102. Response.Write ("<b>")
    103. Response.Write iCount
    104. End If
    105. %>
    106.   </b>
    107.  
    108. </div>

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Location
    world
    Posts
    19

    Re: Error in update please help

    techwiz thank you for replay.
    but i already close the database and rest it.
    could you please clear it for me?
    and thanks

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Location
    world
    Posts
    19

    Re: Error in update please help

    any help please?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width