*** update.aspx ***
....
....
myCommand=new oledbcommand("update tblEmployee....", myConn)
myCommand.executeNonQuery
response.redirect("display.aspx")
*** display.aspx ***
.....
.....
myDataReader=mycommand.executeReader
myDatagrid.datasource=myDataReader
myDatagrid.databind
This is the second project I notice this, whenever I make change to a record in the table(in this case the employee table) with update.aspx and is redirected to display.aspx, it doesnt display the most updated records. But if I press F5 to refresh display.aspx(making absolutely no change to code or whatsoever), I will see the change i made in update.aspx. Also, if I add code to the display.aspx before displaying records to have the thread sleep for 1 second, the problem does not exist.
Am I the only one who noticed this? Or am I doing something not properly?Your display.aspx page may still use the cache.
Hello Jimmy,
Dont think so, when I first noticed the problem, I thought caching was the problem. But not likely, I made sure I added:
Response.Buffer = True
Response.Expires = 0
Response.CacheControl = "no-cache"
Didnt help, also I asked myself if it is displaying from the cache, why does it suddenly change its mind as soon as I press F5/refresh.
The code does not seem to have error
Wierd guess !! you can check you IE settings by going to IE->Tools->General Tab->Group Temporary internet files->Settings->Check for newer version of...
Is it set to never??
Hi there,
My machine is set to Every visit to the page. Again, if the reason is because that IE setting is set to Never, why will it refresh with new data when I press F5 one second after the page first loads? And why will it display new data if I force it to sleep for 1 second before reading in the data?
This happens not only on this machine, it happens on my machine at the office, my users' machines. For the last application that had this problem, my work around is to force a 1 second sleep, I dont know how safe that is, it might work in some cases and not others. Thats why I post here to see if anyone else have the same problem, because this application I am writing now, seeing the most updated data on that display.aspx is very critical.
How are you handling Page_load code?in the other page
I had faced the prob on my PC which was due to IE settings
It used to work same way as ur code is working....
This is whats in my page_load:
sub page_load
dim myDA as oledbDataAdapter
dim myTable as new DataTable("tblCart")
dim myCommand as new oledbCommand
dim myDR as oledbDataReader
dim strSQL as string
dim strCart as string
Response.Buffer = True
'Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
myConnection=new oledbconnection(ConfigurationSettings.AppSettings("ConnectString"))
myConnection.open
myCOmmand.Connection=myConnection
strSQL="select ItemDescription, ListingType, ListingID, CartID, PackageDescription, PackageName, PackagePrice, "
strSQL+="OptionDescription, OptionPrice, "
strSQL+="From qryUnionCart "
strSQL+="where sessionID='" & session.SessionID & "' and datePaymentProcessed is null"
trace.warn(OptionPrice)
myCommand.commandText=strSQL
myDR=myCOmmand.ExecuteReader
myDR.read
trace.warn(myDR("OptionPrice"))
............
I did a trace.warn for optionprice because I updated the OptionPrice in the previous page. The trace didnt show new data, well, not until I press F5. As you can see, this is a shopping cart, not showing the updated data is just not acceptable. =(
Try handling PostBack and see if it works
Assuming you are writing in Codebehind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
if not Page.IsPostBack then
...
End ifend sub
Thanks again for the reply but nope, didnt help. I am so convinced it is a bug.
Please also try
Response.Cache.SetNoServerCaching();
and/or
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Thanks for the suggestion.
Added both, still the same, only see new data when I press F5.
Did you try this from a browser on the server itself, just to make sure there's no proxy between the server and the browser?
I am working on this application on my development machine which has IIS installed.
The problem exists in both cases:
1. Browser: my development machine. Webpages: server on the same machine.
2. Browser: my development machine. Webpages: my hosting company's server.
What database are you using? Did you try to run the two queries directly from a SQL console?
I see another problem with your code: the response is redirected before you close the connection. This could explain the latency as the connection gets actually closed (and perhaps an implicit transaction gets committed) only on the next garbage collection.
Try closing the connection explicitly.
oh my god!!!!! You've got a point there.....
Yes the connection is not closed and disposed until it hits the page_dispose event. I always use page level connection object so all subs/functions within my page will share one connection. That way I dont have to create, open, close, dispose database connection each time I need to read/update records, save time and network traffic.
And guess what, you are right. Within that update procedure, I created a procedure level connection for my update and close/dispose the connection before the redirect. This time I see new, most updated data on my checkout page. Yay!!!! Misery solved, okay its not a bug =P
Now, I guess for all the procedures that redirect to a different page, they must have their own procedure level connection(of course if a connection is needed). Correct? Yes I am pretty sure it is, but is it how you guys do it?
Thanks bleroy, you the man!!
No comments:
Post a Comment