Hello friends here is some question.
VB Code:
var connect = Server.CreateObject( "ADODB.Connection" ) connect.Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\visitors.mdb;User Id=admin;Password=;" ) var rs = Server.CreateObject( "ADODB.Recordset" ) rs.Open( "SELECT Counter FROM Visitors", connect, adOpenStatic, adLockOptimistic ) if ( !rs.EOF ) { rs( "Counter" ) = rs( "Counter" ) + 1 rs.Update } rs.Close connect.Close rs = connect = null
It’s not the most efficient means of updating a counter, but never mind that. This is about concurrent access.
The code above will work, but if two visitors hit the page at exactly the same time then one process won’t wait for the other to conclude. In the worst case one of the processes will abort with an error, saying that the database is locked. You could use a try/catch block, but then you’d need some wait-and-try-again logic, which would be extremely clumsy.
How can we write this code to avoid runtime errors?




Reply With Quote