Solved

Porblem with SQLBulkCopy when Column is Primary Key with UniqueIdentifier

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

730 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