Link to home
Start Free TrialLog in
Avatar of EYoung
EYoungFlag for United States of America

asked on

Log file for MS SQL Server is full

I have written a Visual Basic application that is attempting to write 120,000 records to a table in a Microsoft SQL Server database.

However, as I add the records, the adding process slows down to a crawl.  After adding 50,000 records, I aborted the add job as it was adding records very, very slowly.

Upon looking at the available space on the drive, I found that there was just a few megabytes left.  When I tried to delete the 50,000 records, MS SQL Server gave me an error message saying that the transaction log file for the database was full and said I should backup the transaction log for the database to free up some log space.

As I don't do checkpoints, I don't care about the transaction log.  So how can I get around this problem when I want to add 120,000 records at one time?  Do I need to turn the transaction log off somehow?

Thank you for your input.
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

In the database, set Truncate Log On Checkpoint flag, this will not log the transactions to the log file and you should get your inserts in without any problems. I am not aware of a way of doing this other than on the server itself though so you would have to be very careful if you required logging of other transactions.
Avatar of EYoung

ASKER

I checked the Truncate Log On Checkpoint checkbox for the database and re-ran the job.  The job is not running any faster.

I use the .AddNew and .Update commands to put the new records into the table.  Should I be using the .Insert command to make it run faster or is there something else I am overlooking?

Thanks for any help.
Avatar of Éric Moreau
Using Connection.Execute "INSERT INTO ..." is often faster then the the ADO methods
Avatar of EYoung

ASKER

I have not used the Connection.Execute "INSERT INTO..." command before.  Could you provide a simple example?

The code I usually use is:

        Set rsLines = New ADODB.Recordset
        rsLines.Source = "Select * from Lines " & _
            "Where Line = '@&)'"
        Set rsLines.ActiveConnection = cnSQL
        rsLines.LockType = adLockOptimistic
        rsLines.CursorType = adOpenKeyset
        rsLines.Open
       
        rsLines.AddNew
        rsLines.Fields("Line") = Mid(mRecordID, 4, 3)
        rsLines.Update


If I change to the Connection.Execute command, will that really make a difference or will there only be a minor improvement?  (I need to find a way to significantly improve the input speed.)

Right now the input starts out adding 100 records in about 5 seconds.  However, after every 10,000 records are added the time to add 100 records increases by about 5 more seconds.  So after adding 40,000 records, the time to add the next 100 records has reached 20 seconds or so.  At that rate it will take a long time to add 120,000 records.  Help.

Thanks for the assistance.
You may 50% gain because all your lines can be replaced with:

cnSQL.execute "Insert INTO Lines(Line) VALUES ('" & Mid(mRecordID, 4, 3) & "')"

Avatar of EYoung

ASKER

emoreau,

The actual SQL table has about 70 fields.  What would the code look like for say 3 fields?  Would it look like:

   cnSQL.execute "Insert INTO Lines(Line) VALUES ('" & Mid(mRecordID, 4, 3) & "')", Lines(Size) VALUES ('" & "Mid Size" & "')", Lines(Color) VALUES ('" & "Blue" & "')"

Thanks for the help.
This way:

cnSQL.execute "Insert INTO Lines(Line, Size, Color) VALUES ('" & Mid(mRecordID, 4, 3) & "', 'Mid Size', 'Blue')"
Avatar of EYoung

ASKER

I understand (thanks) but to do that with 70 or so fields would get fairly complex.

I just can't believe that adding 120,000 records would bring MS SQL Server to its knees.  I have already set the Truncate Log On Checkpoint but that does not seem to help.

Any other ideas?
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EYoung

ASKER

I am closing out this question as I won't be able to test that until next Monday.  Thanks for your help.