U
Usenet User
I am programmatically importing lots of rows from dBase 5 into SQL and
want to get an idea what the optimal approach would be for this
scenario.
Currently I'm doing the following:
1) Using OleDbConnection, OleDbCommand and OleDbDataReader to read the
rows from dBase tables;
2) Putting the extracted data into a DataSet;
3) Once the number of rows in the DataSet reaches, say, 1000, I'm
using SqlDataAdapter to submit the data to the database. This step
creates a transaction, issues an INSERT statement for each row in the
DataSet, then commits the transaction.
4) Go to Step 1 and repeat until all data is processes.
The above is inefficient and slow even if the both database
connections are kept open during the whole batch process. For example,
50,000 rows get processed in around 30 seconds.
On the other hand, if I use Import and Export Wizard, the same task
(dBase -> SQL) takes less than 5 seconds.
Out of curiosity, I used SQL Profiler to trace the Import and Export
Wizard to see what it's doing. The last statement in the log is as
follows:
insert bulk [DatabaseName].[dbo].[TableName]
(
"Field_1" float,
"Field_2" float,
"Field_3" nvarchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS,
...
(other table fields here)
...
)
with
(
check_constraints
)
As you can see there is no FROM clause. Also, it's "insert bulk", not
widely-known "bulk insert". (???)
My goal is to achieve the same (or similar speed) with ADO.NET, if
possible. But how?
Also, DTS is not an option, because the tables I'm dealing with change
from batch to batch (different table names, not schema)
Thanks!
want to get an idea what the optimal approach would be for this
scenario.
Currently I'm doing the following:
1) Using OleDbConnection, OleDbCommand and OleDbDataReader to read the
rows from dBase tables;
2) Putting the extracted data into a DataSet;
3) Once the number of rows in the DataSet reaches, say, 1000, I'm
using SqlDataAdapter to submit the data to the database. This step
creates a transaction, issues an INSERT statement for each row in the
DataSet, then commits the transaction.
4) Go to Step 1 and repeat until all data is processes.
The above is inefficient and slow even if the both database
connections are kept open during the whole batch process. For example,
50,000 rows get processed in around 30 seconds.
On the other hand, if I use Import and Export Wizard, the same task
(dBase -> SQL) takes less than 5 seconds.
Out of curiosity, I used SQL Profiler to trace the Import and Export
Wizard to see what it's doing. The last statement in the log is as
follows:
insert bulk [DatabaseName].[dbo].[TableName]
(
"Field_1" float,
"Field_2" float,
"Field_3" nvarchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS,
...
(other table fields here)
...
)
with
(
check_constraints
)
As you can see there is no FROM clause. Also, it's "insert bulk", not
widely-known "bulk insert". (???)
My goal is to achieve the same (or similar speed) with ADO.NET, if
possible. But how?
Also, DTS is not an option, because the tables I'm dealing with change
from batch to batch (different table names, not schema)
Thanks!