Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Software > ADO Data > What's the best...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 16 Topic 4200 of 4320
Post > Topic >>

What's the best way to open a recordset for insert only?

by =?Utf-8?B?U3BlbmNlcg==?= <Spencer@[EMAIL PROTECTED] > Apr 8, 2008 at 08:04 AM

So I found myself having to im****t a boatload of multimillion-line text
files 
into SQL Server.   Because of idiosyncrasies in the data, BULK INSERT and
DTS 
proved impracticable.   Which meant writing a standalone program to do it.


I needed to code a (VB6) class that took care of the idiosyncrasies.  The 
object has a method called Activate() that opens a recordset which
verifies 
the data structure of a destination (ADO) table, and one called PutValues
() 
that inserts a single record into the table by calling AddNew, setting 
values, and then calling Update.

rs.CursorLocation = adUseClient
rs.Open m_rsname, m_conn, adOpenStatic, adLockBatchOptimistic, adCmdTable

It should be apparent that I'm using batch updates: There's a "driver"
class 
that copies rows with PutValues() for 2 seconds, then performs a batch 
update, then updats a progress bar on a dialog. 

This worked reasonably well, but the Activate() method creates a query to 
return all the records in the table.  When the table (in a test DB) has 
millions of records in it already (and this can't be avoided, several 
multimillion-line text files have to be appended into the same table) , it

can take up to several minutes just to open the recordset.   

So, I made a second class whose Activate() method opened the recordset
this 
way:

rs.Open "SELECT TOP 0 * FROM " + m_rsname, m_conn, adOpenStatic, 
adLockReadOnly, adCmdText

The recordset was used only for the table structure validation and the 
inserts are done by building INSERT commands as strings, executed against
the 
connection object.  It mimics "batch updates" by having PutValues() merely

collect the value into a big array of arrays of variants, and the 
BatchUpdate() method creates a big string of INSERT commands separated by 
semicolons. 

Unfortunately, this is much slower than the original class, which used a 
recordset.   It inserts 45-ish records per tick of the progress bar where
the 
original class inserted several hundred per tick.

So it was a failed experiment, and it looks like I'll have to use the 
recordset.   But I'm wondering if there's a way to open the recordset so
that 
I can call AddNew on it, but doesn't query the entire table first.
 




 16 Posts in Topic:
What's the best way to open a recordset for insert only?
=?Utf-8?B?U3BlbmNlcg==?=   2008-04-08 08:04:01 
Re: What's the best way to open a recordset for insert only?
"Stephen Howe"   2008-04-08 16:23:06 
Re: What's the best way to open a recordset for insert only?
=?Utf-8?B?U3BlbmNlcg==?=   2008-04-08 08:34:00 
Re: What's the best way to open a recordset for insert only?
"Bob Barrows [MVP]&q  2008-04-08 11:40:15 
Re: What's the best way to open a recordset for insert only?
=?Utf-8?B?U3BlbmNlcg==?=   2008-04-08 09:06:01 
Re: What's the best way to open a recordset for insert only?
"Stephen Howe"   2008-04-08 16:41:03 
Re: What's the best way to open a recordset for insert only?
"Bob Barrows [MVP]&q  2008-04-08 11:25:46 
Re: What's the best way to open a recordset for insert only?
=?Utf-8?B?U3BlbmNlcg==?=   2008-04-08 09:08:01 
Re: What's the best way to open a recordset for insert only?
"Bob Barrows [MVP]&q  2008-04-08 13:03:08 
Re: What's the best way to open a recordset for insert only?
=?Utf-8?B?U3BlbmNlcg==?=   2008-04-08 10:14:01 
Re: What's the best way to open a recordset for insert only?
=?Utf-8?B?U3BlbmNlcg==?=   2008-04-08 11:53:00 
Re: What's the best way to open a recordset for insert only?
"Bob Barrows [MVP]&q  2008-04-08 15:03:46 
Re: What's the best way to open a recordset for insert only?
"Bob Barrows [MVP]&q  2008-04-08 17:30:52 
Re: What's the best way to open a recordset for insert only?
=?Utf-8?B?U3BlbmNlcg==?=   2008-04-11 07:40:03 
Re: What's the best way to open a recordset for insert only?
"Bob Barrows [MVP]&q  2008-04-08 11:56:49 
Re: What's the best way to open a recordset for insert only?
=?Utf-8?B?U3BlbmNlcg==?=   2008-04-08 09:19:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 14:52:44 CST 2008.