Link to home
Start Free TrialLog in
Avatar of rmcafee
rmcafee

asked on

DMO: Identity column trashed by bulk copy

I'm using the SQL-DMO BulkCopy object in VB 5 to transfer data between servers. It is important to maintain the existing identity values since they are referenced by other tables, so I set the BulkCopy.IncludeIdentityValues property to "true" on both the export and import sides, but the identity values are regenerated by SQL Server nonetheless when the import is done.  I also tried running the "set tablename identity_insert on" query before doing the import, which normally would allow explicit insertion of identity values, but it made no difference.  Any ideas?
Avatar of odessa
odessa

Try to set "IncludeIdentityValues" to false
and then run "set tablename identity_insert on" query
what's happend
Avatar of rmcafee

ASKER

OK, I tried all 4 permutations of BulkCopy.IncludeIdentityValues = true/false and Database.Execute("set identity_insert tablename on/off").

The resulting exported data file doesn't have any identity values in it, regardless of what I do with these flags.
ASKER CERTIFIED SOLUTION
Avatar of gmoriak
gmoriak

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
Use the option
-E with bcp (explicit identity)
when loading data, this will allow you to keep the identity column as it comes with the file.