I've taken a pretty close look at your code, and compared it to the orignal, which worked for me. I can't see any functional difference that would cause the second example to not work. You've found a workaround, although I think it's pretty strange that you have to close the source table. Still, this is an unconventional way to deal with getting a PK, as I and others have pointed out.