There are two general strategies that you can use to ensure that this problem does not impact you. First, you can use transactions (as another author pointed out).
However from a performance perspective, it may be faster for you to manually track Id numbers. You can do this by using a global id in the database. A rolling number that makes ids in the system globally unique.
Lets say the global id is 100 and you know that you are going to need 6 ids. Then you write out 106 to the global id row in the global id table... then you use 101 for the first entry, which is the foreign key in the 102 data point and so on. This improves performance considerably when working on large data sets.
So if you need to make 100 new inserts this might be a good idea. If you only need 6 at a time.. use transactions...
As suggested by jmucchiello in comments. You can use an Update statement to ensure that another process is not writing to the global id entry. Something like
update globaltable set id = 106 where id = 100
I can see that I am getting modded down on this answer, but this really is the best strategy if you have a million rows to import... oh well...
-FT