Four min is way too long. You need to split up what you are doing so that the final insert is a single statement with all the data already on the box.
So in general you can follow the following steps, although each DB has its own special bulk operations.
- Collect all the data before you even talk to the database
- Insert that data into a temp table that won't lock any other processes
- Check there are no constraints that will fail for the rows
- Copy the data over from the temp table to the real table in one go.
Edit - SO from your edit it looks like
The way you haveare doing it with a sproc onlinked database means that the database itself doingwill be running that select while all the collectiondata downloads from the external resourceother database.
This is bad. You don't wantBring the database to do any work like calling 3rd parties or looping through files. Do all thatdata in thewith an application on a seperate machine.
Its generally good advice not to use any sprocs at all. As then you will know for sure that you don't have any business logic in theminstead. Following the steps above