How do i lock a table to prevent reading whilst data is populated


I have a legacy business application that outputs data to DBF files.
One facet of the system is Stock Control, and i am writing a number of Crystal Reports based around the stock data.
In the absence of any real-time connection to SQL, I have an SSIS package that runs every 5 minutes, taking approximately 40 seconds to complete.

1. Launches legacy Export application to output stock data to a DBF file
2. Imports DBF content into temp table.
3. Truncates destination table in SQL
4. Copies data from temp table into destination table using a oledb data flow.

All quite simple. (I'm not a programmer by any stretch of the imagination!)

My problem is that, during step 4, I want to lock the destination table from being read whilst data is being imported.  The reason being that, if a report were run whilst rows were being written, it could result in a very misleading report; and with the frequency the routine is running this is quite a likely scenario.

I've placed step 4 within a transaction but I am still able to read from the table whilst rows are being written.

Can someone offer any suggestion as to how i can lock the table from reads whilst rows are being written?  I would rather the report 'pauses' for a few seconds before reading complete data, rather than potentially returning incomplete data.

Many thanks!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can exclusively lock the table with TABLOCKX hint. Check the following link:-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CAMSYSTEMSAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.