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.IncludeIdentityVa lues 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?
ASKER
OK, I tried all 4 permutations of BulkCopy.IncludeIdentityVa lues = 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.
The resulting exported data file doesn't have any identity values in it, regardless of what I do with these flags.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
-E with bcp (explicit identity)
when loading data, this will allow you to keep the identity column as it comes with the file.
and then run "set tablename identity_insert on" query
what's happend