I have an import routine that takes a generic file (Excel, CSV, Fixed
length, PDMS BOM, XML, etc) and maps fields to a temp import table on
the server, in the field mapping there may be functions specified so the
user may put in "Mid([DocNumber,12,3)" as a value to go into FieldX.
I've tried 3 methods of getting the data from a linked table (CSV file)
to the SQL Server, each having some drawbacks.
Method 1: DAO, pokes each record in one at a time.
Drawback: Extremely slow (17.5 minutes for 76,000 rows)
Drawback2: Took a helluva lot more code and time to write than methods 2
and 3 so if it were a person I'd have thumped it by now :-).
Method 2: Build a query and execute with .Execute method
Quick (2.5 minutes for 76,000 rows)
Drawback: No visual feedback, looks like PC hung for 2.5 minutes.
Method 3: As 2 but .RunSQL method.
As quick as 2 and a progress bar to boot.
Drawback: Errors are either vague (e.g. "inserted null into field that
is not variant type" ok but which field?) or handled by DoCmd and not by
my program (e.g. "x records not appended due to key violation") as vague
as the first with the added headache that the first my program will know
about it is if the user cancels then the error message is that the user
cancelled, which doesn't tell the program what was wrong with the data.
Methods 1 & 2 give concise error messages, e.g. "Cannot insert null into
column xyz, insert fails", which is more helpful.
I must say I was surprised at how much faster the query method was to
DAO, I knew it would be faster but not that much difference!
Before I investigate anything else as a viable alternative to
transferring records (and manipulating them en route) I wondered if
anyone else had any ideas or (better still) experience of a better way.
One way I thought of was to build singular SQL statements rather than
the batch statement in methods 2 & 3 then execute batches of the singlar
inserts, perhaps all at once or in batches of 1000 or something (not
sure how much SQL I can poke into the server for execution in one go).
--
This sig left intentionally blank