CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2012
    Location
    Prizren
    Posts
    37

    Post How to check lines in a text file with rows in database?

    Hi again. I'm having hard time how to solve this problem. I have a text file with some call records in it. Each call record states a line in that text file. And what I want to do is that parsing to database with a 100% success rate. Due to sometimes the SQL connection might get buggy or stop or w/e so it came to my mind that I should make some function or maybe a stored procedure to check whether the requested/selected or whole lines in that text file have been successfully added or not to the database. Let's assume I have 10 lines in a text file called "log.txt" like:
    call line 1
    call line 2
    call line 3
    call line 4
    call line 5
    call line 6
    call line 7
    call line 8
    call line 9
    call line 10
    And assuming that the SQL connection to the database got stuck somehow(buggy) and it stopped inserting those lines to their respectively columns. Let's say it parsed lines from 1-6 and it stopped there, that's where I need the app to tell me that it stopped and continue inserting immediately where it stopped at to the end from 6-10th line. What am I supposed to do? The smoothest way so that the processor doesn't get overwhelmed (in case there are like hundreds of thousands lines). And should it be written in SQL as a stored procedure or written as a function from VB side.
    Toolkit : Microsoft Visual Studio 2010 Ultimate - VB.Net language & Microsoft SQL Management Studio 2005 - SQL Database.
    Last edited by Venn; March 19th, 2012 at 10:48 AM.

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to check lines in a text file with rows in database?

    I would suggest you to look at it from a different point of view:
    you could take advantage of transaction - do the inserts inside a transaction. If something goes wrong for one line, you roll back the whole an try again from the first to the last. Could this apply to your case?
    Last edited by Cimperiali; March 21st, 2012 at 04:45 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Feb 2012
    Location
    Prizren
    Posts
    37

    Re: How to check lines in a text file with rows in database?

    It would definitely apply to my case. But one question just fired my mind. What if the file that has been inserted line by line once and after some day/s has been overwritten and the transaction-insert method. How would it work, should it overwrite the rows, duplicate or with proper manipulation check if the same lines are already recorded as rows in DB except for those that hasn't been? E.g. if 100 lines were properly inserted and the next one wasn't...would the transaction-insert go again from 1st line to the 101th? If not than I'd like to see how would you cover the transaction-insert method because I'm a new to database manipulation.

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to check lines in a text file with rows in database?

    That is a different story: transaction is to ensure the insert are done as a whole, in case something goes wrong during the process while it is going on (you spoke of a matter in connection, for example). But if you have to manage with updates and duplicates, you should:
    code your insert to insert only if line does not exists.
    code to update if the line exists and one or more values are different f
    code to do nothing if line already exists and all values are the same.
    You could put all this logic inside a stored procedure if you're familiar with it.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to check lines in a text file with rows in database?

    VS2011 can use a LOCAL DATABASE. which you can sync when online. Used with phones right now.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

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

Featured