This is a continuation of this next topic . This is all with .Net 2.0 ; For me at least.
Essentially, Marc (OP on top) tried several different approaches to updating the MS Access table with 100,000 records and found that using a DAO connection was about 10 to 30 times faster than using ADO.Net. I went almost the same way (examples below) and came to the same conclusion.
I think I'm just trying to understand why OleDB and ODBC are so slower, and I would like to hear if anyone found a better answer than the DAO from this post in 2011. I would really prefer to avoid DAO and / or Automation, as they will require the client machine to either distribute Access or the database engine (or I'm stuck with DAO 3.6, which does not support .ACCDB).
Initial attempt; ~ 100 seconds for 100,000 records / 10 columns:
Dim accessDB As New OleDb.OleDbConnection( _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ accessPath & ";Persist Security Info=True;") accessDB.Open() Dim accessCommand As OleDb.OleDbCommand = accessDB.CreateCommand Dim accessDataAdapter As New OleDb.OleDbDataAdapter( _ "SELECT * FROM " & tableName, accessDB) Dim accessCommandBuilder As New OleDb.OleDbCommandBuilder(accessDataAdapter) Dim accessDataTable As New DataTable accessDataTable.Load(_Reader, System.Data.LoadOption.Upsert)
Anyway, I thought it was really strange, so I tried several options for the same:
- Disabling OleDB for ODBC
- Quoting from a data table and executing an INSERT statement for each row
- This is what .Update is anyway
- Using ACE Provider Instead of Jet (ODBC and OleDB)
- Starting a data adapter update from a DataReader.Read cycle
- Due to disappointment; It was fun.
Finally, I tried using DAO. The code should basically do the same; besides this, obviously not, because it works after ~ 10 seconds.
Dim dbEngine As New DAO.DBEngine Dim accessDB As DAO.Database = dbEngine.OpenDatabase(accessPath) Dim accessTable As DAO.Recordset = accessDB.OpenRecordset(tableName) While _Reader.Read accessTable.AddNew() For i = 0 To _Reader.FieldCount - 1 accessTable.Fields(i).Value = _Reader.Item(i).ToString Next accessTable.Update() End While
A few other notes:
- Everything is converted to Strings in all examples to try to keep everything as simple and consistent as possible.
- Exception: in my first example, using the Table.Load function, I’m not because ... well, I really can’t, but I did basically the same thing when I looped the reader and created the insert commands (this is what he does, anyway). It did not help.
- For each field ... Next to field (i) against field (name) there was no value for me
- Every test I ran started with an empty, pre-built data table in a recently compressed Access database
- Loading data into a data table in memory takes ~ 3 seconds
- I don’t think this is a problem with data marshaling, because a Marc message showed that downloading a text file through Automation is as fast as a DAO - if anything, it should not marshal data when using ODBC / OleDB, but when using Automation
- All this bothers me more than necessary, because it makes no sense
Hope someone can shed some light on this ... it's just weird. Thanks in advance!
Karter Apr 03 '13 at 13:18 2013-04-03 13:18
source share