Solved

Porblem with SQLBulkCopy when Column is Primary Key with UniqueIdentifier

Posted on 2012-03-10
2
1,138 Views
Last Modified: 2012-08-13
I am trying to insert data into a table with a primary key having default value of newsequentialid()  using SqlBulkCopy.

Prior to insert the data by examining DataReader object I see that all PK values are Guid.Empty(represented by 0000-000…) .

However when I try insert the data the SQlBulkCopy  tries to  insert PK with Guid.Empty values and I get unique identifier conflicts for PK column.

Is there a way to exclude Pk from insert or tell SQLBulkCopy not insert data in column with UniqueIdentifier property?   I have tried all SqlBulkCopyOptions Enumerations with no success.
0
Comment
Question by:Berico
2 Comments
 
LVL 15

Accepted Solution

by:
navneethegde earned 500 total points
ID: 37705252
Hi!
try if you are inserting Id or primary key value
SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity)

Else
And also try to have ColumnMapping and remove the Primary Key Mapping

Thanks!
0
 

Author Closing Comment

by:Berico
ID: 37710032
navneethegde;

Thanks ColumnMapping did the trick.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

747 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

13 Experts available now in Live!

Get 1:1 Help Now