473,395 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to prevnt duplicate PKs when using SqlBulkCopy

Hi All,

I am using the SqlBulkCopy for import data into ms sql 2005. I ran a test
when Imported the same 2 files one after another and each one had the same
PK values, but somehow it went through and got duplicate PKs. I thought that
ms sql will gen an err.

Any idea?

Thanks,

Steve
Oct 20 '08 #1
2 1176
Do it again....You must be mistaken..
Double check that you have Primary Key set to what you think it is...

George.

"SteveB" <St****@Hotmail.comwrote in message
news:O9**************@TK2MSFTNGP02.phx.gbl...
Hi All,

I am using the SqlBulkCopy for import data into ms sql 2005. I ran a test
when Imported the same 2 files one after another and each one had the same
PK values, but somehow it went through and got duplicate PKs. I thought
that ms sql will gen an err.

Any idea?

Thanks,

Steve
Oct 21 '08 #2
if you have a primary key defined on the table it will gen an error, as
dups can not be inserted. if you drop it before the load, then you must
cleanse the data before loading.

-- bruce (sqlwork.com)

SteveB wrote:
Hi All,

I am using the SqlBulkCopy for import data into ms sql 2005. I ran a test
when Imported the same 2 files one after another and each one had the same
PK values, but somehow it went through and got duplicate PKs. I thought that
ms sql will gen an err.

Any idea?

Thanks,

Steve

Oct 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
2
by: Spam Catcher | last post by:
Hi all, Does .NET 2.0's SQLBulkCopy class work with SQL Server 2000? Thanks!
4
by: Chris | last post by:
I have created a datatable from a csv file. One of the columns is an integer which sometimes can be blank. When it is blank I add a dbnull.value to the column when I add to the datatable. This...
3
by: 01423481d | last post by:
Hi All I have created an interface to insert 70000 records from a csv file to the Pervasive database one by one using ordinary sql statement, but the performance is not satisfactory (it takes...
5
by: hemant kamble | last post by:
Hi all, Can it is possible to prevnt the user to enter data throught keyboard and allow user to enter data through scaner (barcode scaner). how it's possible. Help me.
5
by: TheSteph | last post by:
Using : MS-SQL 2005 / .NET 2.0 / VS2005 I have two server with the same database def but different data. I would like to import data from Server2.TableA to Server1.TableA. If a row doesn't...
2
by: Amar | last post by:
Hi, I need to insert a large amount of records pretty frequently through my application. The quickest way to achive this seems to be SQLBulkcopy class. I have implemented the solution using the...
2
by: SteveB | last post by:
Hi All, I am using the SqlBulkCopy for import data into ms sql 2005. I need to import multipe files which could be from 1 to GB each. Is there need to use a garbage collection for this purpose...
0
JamieHowarth0
by: JamieHowarth0 | last post by:
Hi guys, Quick q - I'm working on an ASP.NET C# web app (but my question is framework-related, not specific to my app). The SqlBulkCopy class - can it return values (thinking primary key/s here)?...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.