Question

I know VB6 is a bit out of date but that's the application at the moment that I have inherited.

I have to do an update based on the results of an array to an access table.

The array contains a double and the id of the record to update.

The issue is that there are 120,000 records to update but on a test it took 60 seconds just to run it on 374 records.

This is my update code

Dim oCon As New ADODB.Connection
Dim oRs As New ADODB.Recordset
Dim string3 As String
oCon.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path &"\hhis.mdb;Pwd=/1245;"

oCon.BeginTrans

For i = 0 To maxnumberofrecords - 1

string3 = "UPDATE YourRatings SET yourRatings=" & YourTotalRatingsAll(i) & " Where thisID = " & thisID(i) & ";"

oRs.Open string3, oCon, adOpenStatic, adLockOptimistic

Next i
oCon.CommitTrans
oCon.Close

I added the "CommitTrans" based on some other articles that I had read but that doesn't seem to increase the speed.

The other problem is that I am going to have to run another query to rank the highest(1) to lowest (374) and update the db again...although I can probably do something with the array to add that column at the same time.

This seems quite slow to me especially when other post mention 200000 records in 14 seconds.

Have I just missed something? Would it be quicker to load from a text file?

Thank you in advance for any help.

Mal

No correct solution

OTHER TIPS

With Open you always constructing a new ResultSet object. Try oCon.execute string3 which only sends the SQL to your database without ResultSet overhead.

Ensure that you have an index on thisID.

Maybe your Access DB sits on a network drive. That could have a large performance impact. Try it local.

Why are you using the creaky old Access Desktop ODBC Driver instead of the Jet 4.0 OLEDB Provider?

Why are you opening a Recordset to do an UPDATE instead of calling Execute on the Connection?

Is there any reason you can't open the database for exclusive access to perform this operation? Locking overhead is all but eliminated and "cargo cult" techniques like thrashing with BeginTrans/CommitTrans lose any significance.

Do you have an index on your thisID field in the table?

Please do move to the magic bullet .Net as soon as possible. Your programs will be even slower but we won't have to read all the whinging blaming VB6.

Just to add to Wumpz answer, you might want to try just adding the query directly into the Access database and calling this using parameters. This SO thread says far more about it.

Parameters are far more stable and less hackable than injection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top