Results 1 to 15 of 15

Thread: [02/03] How to make tons on insert statements more effecient?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    12

    [02/03] How to make tons on insert statements more effecient?

    Hello I am new here and sort of new to VB.NET. I am trying to write a program that will take the national do not call list for a certain area code, which is given to me in a comma seprated file, and then to check if the number is in a database, if it isn't then to insert it. There are literaly millions of numbers. They way I have written it is so slow because I don't really know how to write database applications. Everytime I check to see if a number exists I open a connection and then run an OleDbCommand and ExecuteScalar then I close the connection. Then if it doesnt exist then I Open another connection and Insert then close. Is there a way I can just open the connection once at the beggined then do all my queries and then close it at the end? Is there something else I can do to speed this up, because the way I have it right now it will take days and days to complete.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [02/03] How to make tons on insert statements more effecient?

    Welcome to the forums. I have two suggestions, but they may not be ideal:

    1) You can just open one connection, and leave it open for the duration. There is no need to close it, and that alone should speed up the processing. Just keep changing the command.CommandText to the new query, without ever closing the connection. I guess I'd have to see some code to make a verys specific suggestion there.

    2) I'm not sure what the slowest part of the process is. You might benefit from a stored procedure handling the INSERT, but failing that, why not lump several INSERT statements together. Shoudl be able to separate them with commas. If you tested for five numbers, then lumped (up to) five INSERT statements together, that should speed things up some. Further improvements might be made along these lines, such as searching until five numbers need to be inserted, then inserting them. Etc.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    12

    Re: [02/03] How to make tons on insert statements more effecient?

    Cool thanks for the ideas, Ill try them out

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [02/03] How to make tons on insert statements more effecient?

    What kind of database?

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    12

    Re: [02/03] How to make tons on insert statements more effecient?

    Oracle 8

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [02/03] How to make tons on insert statements more effecient?

    I am not familiar with Oracle but you can write some stored procedures that accept some parameters that you can pass to perform the insert. This should be the faster method.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [02/03] How to make tons on insert statements more effecient?

    Wouildn't it be quicker to load the data into a temproary table using SQL Loader then write a SP to perform the test and insert?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    12

    Re: [02/03] How to make tons on insert statements more effecient?

    I don't know what SQL Loader is so I wouldn't know what would be faster. I guess I could make a stored procedure where I could pass the number and have the database check the number for me. Ill try that out.

  9. #9
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [02/03] How to make tons on insert statements more effecient?

    SQL Loader will load the file directly into the database. It is part of the Oracle applications installed on the system. It is run from the command line. You could have you app call the command line with SQL*Loader and the required parameter file then once the load is finished (I have loaded about 2.5 million records into an Oracle 8 DB in about 2 minutes lilke this) have the app call the SP to process the records.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [02/03] How to make tons on insert statements more effecient?

    So its like SQL Servers bcp?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [02/03] How to make tons on insert statements more effecient?

    Yes it is. The control file tell the SQL*Loader where the data is in the line and what field it goes into.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  12. #12
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [02/03] How to make tons on insert statements more effecient?

    Gary has an idea worth investigating. We do something similiar in MS SQL Server.

    We load the "voter" list for the state - about 4 million rows - using BULK INSERT (the MS SQL version of SQL Loader) into a staging table. This load runs relatively quickly

    Then we use stored procedures to process and match this data against membership files.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    12

    Re: [02/03] How to make tons on insert statements more effecient?

    How do I have my application load all the data into SQL loader. I have three fields, the area code, the phone, and the full number.

  14. #14
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [02/03] How to make tons on insert statements more effecient?

    DO you have access to the Oracle Complete Reference Guide? If you do then there is a complete section in that refernce book that covers SQL*Loader. If not PM me and I'll have to e-mail you a PDF of the chapter as it is too large to post here.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  15. #15

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    12

    Re: [02/03] How to make tons on insert statements more effecient?

    Thanks for your help but I found out how to use it. Its a lot faster. Thanks

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