Solved

Porblem with SQLBulkCopy when Column is Primary Key with UniqueIdentifier

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

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

863 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

25 Experts available now in Live!

Get 1:1 Help Now