Solved

Fastest way to load data from a csv stream into access

Posted on 2012-03-28
6
562 Views
Last Modified: 2012-06-21
I have a stream of CSV data that I need to load into an access table. The table is initially blank and this will be the only process running.  There are a few values in the input CSV data that need to be cleaned (dates need to be formatted and some strings need to be escaped).

Currently I have the data in a CSVReader and read the data one line at a time and create a OleDbCommand and set the CommandText for the insert.  I then .ExecuteNonQuery to add the single line to the database and then read the next line from the reader and repeat.

Is there a faster way to get the data into access?
0
Comment
Question by:hotshottools
6 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37778325
CSV, typically denotes a text "file",...but you say that your is a csv "stream"?

Can you save this strem as a file...?
If so, then the import becomes easy.
Just use the Import utility in Access:
External Data-->Import-->Text File-->...

JeffCoachman
0
 

Author Comment

by:hotshottools
ID: 37778342
I'm doing this in code to create the access file and import the data.  My current solution works but seems slow with I'm importing 100,000 records.

My goal is to speed up the code.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37778709
<My goal is to speed up the code.>
"Speed" is a relative term.

Can you state how long this takes in chronological terms...?

Also it seems then that the creation of this stream is what is taking the most time.

Access can only "easily" take in disk files, not streams directly...

Care to post the details of how you are creating the stream?
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 20

Expert Comment

by:clarkscott
ID: 37780403
Can your csv file be saved as a txt file?   If so...
1.  Open Access and LINK to the txt file.  When the 'wizard' appears, check the box for "first row contains headers" (yes or no) and determine the delimiter (tab, comma, etc.).  Now - look for the ADVANCED button.  This will allow you to set up the FILE STRUCTURE for the txt file (dates, text, numbers, etc.).  When finished - SAVE THE SETUP (there will be a button).

Link to the table where this data should go.
Create a APPEND QUERY using the txt link updating to the target table.

You can "adjust" any data formatting, etc. in the update query.

That will run faster.
Scott C
0
 
LVL 10

Accepted Solution

by:
eguilherme earned 500 total points
ID: 37781282
check the comments in this question:
http://stackoverflow.com/questions/7070011/writing-large-number-of-records-bulk-insert-to-access-in-net-c

i have not tested it yet, but apparently using access interop to write to the table is way faster than the ado.net method..
0
 

Author Closing Comment

by:hotshottools
ID: 37782224
Moved from OLEDB command to using interop.dbo and found an initial speed increase of 30%.  I'm sure with a little modifications I can cut the time in half.

Thanks;
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question