Solved

DMO: Identity column trashed by bulk copy

Posted on 1998-10-15
4
328 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:rmcafee
4 Comments
 
LVL 2

Expert Comment

by:odessa
Comment Utility
Try to set "IncludeIdentityValues" to false
and then run "set tablename identity_insert on" query
what's happend
0
 

Author Comment

by:rmcafee
Comment Utility
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.
0
 
LVL 3

Accepted Solution

by:
gmoriak earned 100 total points
Comment Utility
Try running

set tablename identity_insert on

on your source table before the export AND on your destination table before the import.
0
 

Expert Comment

by:bamartino
Comment Utility
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.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now