Solved

DMO: Identity column trashed by bulk copy

Posted on 1998-10-15
4
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Expert Comment

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

Author Comment

by:rmcafee
ID: 1090597
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
ID: 1090598
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
ID: 1090599
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

726 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