473,791 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import large text file to a MS Access database

hi there,

i have a huge large text file (350.000 lines) that i want to import to
a MS Acccess Database, of course i don't want to use Access, but do it
with C#.

i already have tried the AddRow method or Insert, reading each line of
the text file, the problem of course is velocity, it would take more
than 4 hours to add all lines/records to the database.

any suggestion?
than you

Mar 3 '07
14 11265
Does Access support transactions? I didn't think it did. The real answer to
his question is "use SQLServer instead".

Robin S.
---------------------------------------------
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
"rossum" <ro******@coldm ail.comwrote in message
news:v9******** *************** *********@4ax.c om...
>If you load data into an indexed table then each line inserted into
the table also requires an update to the index(es) for that table. By
dropping all the indexing before a bulk load you do not have the
overhead of re-indexing during the run.

Or perform the writes within a transaction - indexes are only updated
when the transaction is committed...

Mar 5 '07 #11
"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:28******** *************** *******@comcast .com...
Does Access support transactions?
Yep - ever since version 1.0...
http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx
Mar 5 '07 #12
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:e$******** ********@TK2MSF TNGP05.phx.gbl. ..
"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:28******** *************** *******@comcast .com...
>Does Access support transactions?

Yep - ever since version 1.0...
http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx
Well, it supports it with DAO. The question is, does it support doing
transactions with ADO.Net? I thought I had seen a post in the
microsoft.publi c.dotnet.framew ork.adonet group that said it didn't, but I
could be wrong. Wouldn't be the first time; won't be the last. ;-)

Robin S.
Mar 5 '07 #13
Going back in time to ADO we created a link to the text file (via Odbc Text
driver) and then issued a INSERT/SELECT FROM to copy the data from the link
into database proper ... for example;

CREATE "ADOX.Catal og" w_Catalog NO-ERROR.
w_Catalog:Activ eConnection = "<connectio n-string-to-mdb-database>".
CREATE "ADOX.Table " w_Table.
w_Table:Name = "zzData".
w_Table:ParentC atalog = w_Catalog.
w_Table:Propert ies("Jet OLEDB:Link Datasource") =
"<path-in-which-test-file-is-located>".
w_Table:Propert ies("Jet OLEDB:Remote Table Name") = "<name-of-test-file,
eg WSReport#txt>".
w_Table:Propert ies("Jet OLEDB:Create Link") = True.
w_Table:Propert ies("Jet OLEDB:Link Provider String")= "TEXT;HDR=N o".
w_Catalog:Table s:APPEND(w_Tabl e).
.... (and then )
CREATE "ADODB.Connecti on" w_DB NO-ERROR.
w_Sql = "INSERT INTO Booking (<fields>) SELECT <fieldsFROM zzData WHERE
<filter-if-required>".
w_DB:EXECUTE(w_ Sql, OUTPUT w_Cnt, 0).
w_Sql = 'DROP TABLE zzData'.
w_DB:EXECUTE(w_ Sql, OUTPUT w_Cnt, 0).

The code is from a non .Net 4gl, so "some" conversion is required, I have
placed <around most of the parameter elements - hopefully it will give you
some ideas. The down side is the use of the ADOX com for the schema link
(the "INSERT/SELECT FROM" statement you can do through managed code) - not
sure how much of an issue it will be though.
"rossum" <ro******@coldm ail.comwrote in message
news:v9******** *************** *********@4ax.c om...
On 3 Mar 2007 12:14:57 -0800, "mfrsousa" <mf******@gmail .comwrote:

rossum wrote:
For a bulk load of a database, such as you describe, it is often
better to switch off indexing on the affected tables before starting
the load and then rebuilding the indexes from scratch after the bulk
load has finished.

rossum
Right i was just reading this bulk thing (sorry my ignorance), the
problem is that i have tried something like this:
/*************** *************** ******** CODE
*************** *************** */
string conn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=|
DataDirectory|\ \db.mdb";
OleDbConnection oleconn = new OleDbConnection (conn);
oleconn.Open();

string sqlstr = "BULK INSERT INTO tblExtData (ext_disc, ext_num,
ext_track, ext_artist) FROM 'c:\\data1.lst' )";
OleDbCommand olecom = new OleDbCommand(sq lstr, oleconn);
olecom.ExecuteN onQuery();
/*************** *************** ******** CODE
*************** *************** */
and i get this error

Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE',
'SELECT', or 'UPDATE'.
i think that the OleDB doesnt support the bulk command

could you point to some bulk reading or explain better please

thanks
I do not know MS SQL, all my experience was with Oracle SQL some time
ago.

Basically the sequence is:

Delete all indexes for tables to be loaded
Load data into tables
Rebuild/create indexes for tables just loaded

If you load data into an indexed table then each line inserted into
the table also requires an update to the index(es) for that table. By
dropping all the indexing before a bulk load you do not have the
overhead of re-indexing during the run.

Rebuilding the indexes from scratch is faster than trying to keep them
up to date while loading 350,000 lines into a table.

HTH

rossum

Mar 6 '07 #14
On Mar 6, 6:29 am, "Colin Stutley" <Colin.Stut...@ ws.com.auwrote:
Going back in time to ADO we created a link to the text file (via Odbc Text
driver) and then issued a INSERT/SELECT FROM to copy the data from the link
into database proper ... for example;

CREATE "ADOX.Catal og" w_Catalog NO-ERROR.
w_Catalog:Activ eConnection = "<connectio n-string-to-mdb-database>".
CREATE "ADOX.Table " w_Table.
w_Table:Name = "zzData".
w_Table:ParentC atalog = w_Catalog.
w_Table:Propert ies("Jet OLEDB:Link Datasource") =
"<path-in-which-test-file-is-located>".
w_Table:Propert ies("Jet OLEDB:Remote Table Name") = "<name-of-test-file,
eg WSReport#txt>".
w_Table:Propert ies("Jet OLEDB:Create Link") = True.
w_Table:Propert ies("Jet OLEDB:Link Provider String")= "TEXT;HDR=N o".
w_Catalog:Table s:APPEND(w_Tabl e).
... (and then )
CREATE "ADODB.Connecti on" w_DB NO-ERROR.
w_Sql = "INSERT INTO Booking (<fields>) SELECT <fieldsFROM zzData WHERE
<filter-if-required>".
w_DB:EXECUTE(w_ Sql, OUTPUT w_Cnt, 0).
w_Sql = 'DROP TABLE zzData'.
w_DB:EXECUTE(w_ Sql, OUTPUT w_Cnt, 0).

The code is from a non .Net 4gl, so "some" conversion is required, I have
placed <around most of the parameter elements - hopefully it will give you
some ideas. The down side is the use of the ADOX com for the schema link
(the "INSERT/SELECT FROM" statement you can do through managed code) - not
sure how much of an issue it will be though.

"rossum" <rossu...@coldm ail.comwrote in message

news:v9******** *************** *********@4ax.c om...
On 3 Mar 2007 12:14:57 -0800, "mfrsousa" <mfrso...@gmail .comwrote:
>rossum wrote:
>For a bulk load of a database, such as you describe, it is often
>better to switch off indexing on the affected tables before starting
>the load and then rebuilding the indexes from scratch after the bulk
>load has finished.
>rossum
>Right i was just reading this bulk thing (sorry my ignorance), the
>problem is that i have tried something like this:
>/*************** *************** ******** CODE
>************** *************** **/
>string conn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=|
>DataDirectory| \\db.mdb";
>OleDbConnectio n oleconn = new OleDbConnection (conn);
>oleconn.Open() ;
>string sqlstr = "BULK INSERT INTO tblExtData (ext_disc, ext_num,
>ext_track, ext_artist) FROM 'c:\\data1.lst' )";
>OleDbCommand olecom = new OleDbCommand(sq lstr, oleconn);
>olecom.Execute NonQuery();
>/*************** *************** ******** CODE
>************** *************** **/
>and i get this error
>Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE',
>'SELECT', or 'UPDATE'.
i think that the OleDB doesnt support the bulk command
>could you point to some bulk reading or explain better please
>thanks
I do not know MS SQL, all my experience was with Oracle SQL some time
ago.
Basically the sequence is:
Delete all indexes for tables to be loaded
Load data into tables
Rebuild/create indexes for tables just loaded
If you load data into an indexed table then each line inserted into
the table also requires an update to the index(es) for that table. By
dropping all the indexing before a bulk load you do not have the
overhead of re-indexing during the run.
Rebuilding the indexes from scratch is faster than trying to keep them
up to date while loading 350,000 lines into a table.
HTH
rossum
Solution is here, thank you all for the help
http://groups.google.com/group/micro...60421b4295430b

Mar 6 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
18836
by: Rune Johansen | last post by:
Hi, I'm sorry if these questions are trivial, but I've searched the net and haven't had any luck finding the information I need. I need to perform some regular expression search and replace on a large text file. The patterns I need to match are multi-line, so I can't do it one line at a time. Instead I currently read in the entire text file in a string using the code below.
0
4886
by: atse | last post by:
Hi, I am still stick on the text file being imported to database. Can anybody help? I have just done the csv format files. And then I work on text and DAT formats, but I have problem to import these kinds of formats to MySQL ( and MS SQL) Please see the attachments, and the text format is changed from DAT format, delimited by tabs or commas. I can't select and insert them into the database. When I try: select * from thisfile.txt and...
0
2166
by: adrian GREEMAN | last post by:
When I try to import a text file with new data for an existing table I get the error "1148 - the used command is not allowed with this MySQL version." I have tried with both PHPMyAdmin2.3 and with MySQLFront 2.5. Both these GUI programmes have an "import from text file" command which I have used successfully several times to add entries to this table before - running just this MySQL version. I have structured the data in the text...
6
2248
by: jcrouse | last post by:
Here is a sniplet from a text file game name mapp description "Mappy (US) year 198 manufacturer "Namco history "\nMappy (c) 03/1983 Namco. \n\n- TRIVIA: \n\nLicensed to Bally Midway for US manufacture and distribution. (03/1983) \n\n- SERIES: \n\n1. Mappy \n2. Hopping Mappy \n\n0.26 \n\nBugs: \n- \"000\" is displayed on the highscore. If you get more than 30000 pts, it is displayed normally. This happens whether there are...
2
4349
by: bienwell | last post by:
Hi all, Do you have any source code to import data from Excel file or text file into database in ASP.NET program ? Please give me your reference if you have. Thanks in advance
8
3014
by: diasdaman | last post by:
I know how to import text files, but in this case I need to import a text file line by line on an on-the-fly basis, such that the Access will look at the first two digits of a line, and then import the rest of the line based on a given specification into an appropriate table. I'm not that familiar with VBA, but I can pick it up if I need to. But first I want to know if what I want to do is even possible.
0
179
by: Edwin.Madari | last post by:
here is a working code snippet to read from MySQL db. python tutorial has examples of reading from files. put them together to do your task. =================================================== import MySQLdb con = MySQLdb.connect(host='127.0.0.1', port=4321, user='joe', passwd='shmoe', db='tst') cursor = con.cursor() sql = 'select * from YOUR_TABLE'
10
3281
by: sarthur | last post by:
Hi Friends, I am trying to get the last 50 Mb of a large Text file(Over 2 GB) using VB. I have to add this to an Access form so that when the user clicks the button a pop up window asks for the source of the text file and the destination of the output file and then it saves only the last 50 MBytes of the file to the output location. I am not that good in VB programming. I would appreciate if anyone can help me on this? Thanks,...
12
3183
by: Miguel Valenzue | last post by:
I collect traffic data from a machine that outputs text files with the data. I want to import each text file as it's own table into an Access database and do it without having to run the import wizard for each one. As part of this function, I'd like to strip the first 15 lines of data from the dataset, parse in the first 5 columns, and name the table after the information on line 3 which is the name of the street the data was taken from. ...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.