Results 1 to 7 of 7

Thread: fastest upload method for large # of records

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    fastest upload method for large # of records

    I have a VB6 app connecting to a SQL Server 2005 db

    I'm uploading about 15,000 records on a regular basis.
    The records are not very long, mustly numeric.
    Some records go into one table and some go into another.
    Using two Conn.Execute statements for each set of data was just too slow, taking hours.
    THen I wrote a stored procedure that did it, but that wasn't much faster.
    Next I conctatenated entire records one after another with a unique identifier and wrote a stored procedure that uses Pat Index to split the record strings up and send each one to the original stored procedure.
    That worked, but it always timed out. Obviously it would have taken hours to finish.
    So lastly, I broke records into blocks of 50 records (the number I can count on to execute and not time out) and now I use a loop of 300 Conn.Execute statements to send each batch of 50 records to the Pat Index stored procedure.
    Currently, this takes over two hours to complete.

    Have I missed something that would be faster? I've heard people say Pat Index is slow, but I don't know another way to send multiple records up at a time. Also I don't know how to keep SQL Server from timing out on this enormous job.
    Anybody?

    Thanks.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: fastest upload method for large # of records

    Here's how I'd do it... more accurately, this is how I have done it... and with hundreds of thousands of records.... create a table in the database that mirrors what the data looks like raw. Read the data into a datatable, then use the SQLBulkCopy class to feed the data right into the table. Then I run an SProc that processes, scrubs and validates the data. Then I take the good, valid data and put it into it's final table(s).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    Re: fastest upload method for large # of records

    you lost me in the middle

    you're saying the datatable in vb6 right?
    is SQL BulkCopy a class in VB6, in SQl Server, or in the datatable?
    I've never used a datatable before.
    Now, how does bulkcopy work? how can it prevent a timeout with SQL Server?
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: fastest upload method for large # of records

    Bleh... sorry, I missed the VB6 bit... I was thinking .NET.

    hmmmm.... I'm not sure I have a solution then....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: fastest upload method for large # of records

    Can't you perform a Bulk Insert or a DTS?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    Re: fastest upload method for large # of records

    I'm not familiar with DTS or Bulk Insert. How do they work?

    On .Net, yes in that case I know what you mean. I did use the datatable in .Net a few years ago.
    I guess what I could do is have my VB6 app launch the .Net app when it's done, and then have the .Net app do the rest. I think I can get the data loaded into the .Net datatable, and I'm pretty sure I've connected a VB.Net app to a SQL Server db before.
    So, I build this temptable, and then what is next?
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  7. #7
    Junior Member
    Join Date
    Aug 2011
    Posts
    21

    Re: fastest upload method for large # of records

    Bulk Insert works by locking the table, then inserting all the provided rows as fast as possible into the table, then unlocking the table. The INSERT statement works on a single row. It does some housekeeping work, does the insert, and does some more housekeeping. In the case of many INSERT statements, the time spent doing the housekeeping work overwhelms the time spent doing the actual insertion work.

    Bulk Insert works on multiple rows. It will do some housekeeping, then insert all the rows, then do some housekeeping. This minimizes the housekeeping work.

    In VB5, I don't think there's a direct way to perform bulk inserts into SQL Server. There certainly is in VB.NET. If you're unable to migrate your code to a more modern platform, you'll have to consider using external objects or scripts to make the bulk data transfer happen.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width