question

TSF avatar image
TSF asked

0xc0202009 Primary Key Error

I keep receiving the error below when trying to import data from a Flat File source (CSV file) in SQL 2008 R2 Express edition. Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "The statement has been terminated.". An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Violation of PRIMARY KEY constraint 'PK_UoSW_STAGING_TABLE'. Cannot insert duplicate key in object 'dbo.UoSW_STAGING_TABLE'. The duplicate key value is (00492FF894C64BEFAC9C3D1866773CE2).". (SQL Server Import and Export Wizard) I have checked the import source for the primary key SQL says is causing the error but when I find that primary key in the CSV file only one entity exists. I thought perhaps it was due to that particular record so removed this and ran the import wizard again but the same error occurs with a different field. I cannot see how I can get around this when the primary key isn't being duplicated at all. I have also checked other tables within the database to make sure I haven't accidentally imported the CSV to the wrong location. Any help would be tremendous at this stage as this has driven me insane for hours!
sql-server-2008-r2errorprimary-key
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sqlaj 1 avatar image sqlaj 1 commented ·
The error is on the insert statement. Disable the PK constraint on the table you are importing into? Then check after the import is complete to see if there are duplicates? Or just apply the PK constraint again. It will provide feedback if there is an issue.
1 Like 1 ·
mjharper avatar image mjharper commented ·
This may be a stupid question - but is the table dbo.UoSW_STAGING_TABLE empty when you start the import?
1 Like 1 ·
Dave Morrison avatar image Dave Morrison commented ·
As has been suggested above, remove the PK, run the insert then query the table. You'll then see what is doubling up. It could well be a truncation issue, I've seen that a lot (i.e. you've got a key field of 15 chars but its getting truncated to 10 and hence the dupes)
1 Like 1 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.