Solved

Porblem with SQLBulkCopy when Column is Primary Key with UniqueIdentifier

Posted on 2012-03-10
2
1,165 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…

773 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