SQL Server : Statement Conflict - sql-server

I'm working with SCRUBS and I'm trying to run a job on SSMS but I'm getting this error:
Started: 3:41:55 PM
Error: 2015-07-31 15:41:58.03
Code: 0xC0202009
Source: Reports Write new Reports [135]
Description: 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: "The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Reports__ReportT__2D27B809". The conflict occurred in database "SummitCloud_SCRUBS", table "dbo.ReportTypes", column 'ReportType'.".
End Error
Error: 2015-07-31 15:41:58.03
Code: 0xC0047022
Source: Reports SSIS.Pipeline
Description: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Write new Reports" (135) failed with error code 0xC0202009 while processing input "OLE DB Destination Input" (146). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
End Error
DTExec: The package execution returned DTSER_FAILURE (1).
I've looked into the .dtsx file but I can't see anything wrong with the design. The columns [ReportTypes].ReportType and [Reports].ReportType also have the same type. So I'm not sure what the what problem is.
Does anyone know why I'm getting this error, please?
Thanks

Error is specifically
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Reports__ReportT__2D27B809". The conflict occurred in database "SummitCloud_SCRUBS", table "dbo.ReportTypes", column 'ReportType'.".
which means that you are trying to insert something in the FK column ReportType which does not exist as PK in the primary key table
How to correct:
Open database SummitCloud_SCRUBS in SQL Server Management Studio
Open the table dbo.ReportTypes in design view.
See relationships on this table, and find one named FK__Reports__ReportT__2D27B809 and see what is the table for the primary key.
Check that table for valid PK values which can be inserted as FK in the table.
Try to check what are you trying to put in the column.
Hack:
Remove the FK relationship and see what gets in the table.

The error is related to the FOREIGN KEY constraint, not to the data type. It looks like whatever value you are trying to put into that table is not a valid PK in the table ReportTypes

Related

Problem Copying Data from One Database (and Server) to Another (Violation of Primary Key Constraint)

I am trying to get a local copy of our remote database. I cannot do a "copy database" because it will not copy to SQLExpress. So I tried to script with data to recreate on my local, it got all the way to the "end" 3 times and then just said "generate script failed". So I scripted just the schema. All tables are empty, but now I am getting "duplicate key" errors (of course at the very end), like this:
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 OLE DB Provider for SQL Server" Hresult: 0x80004005 Description: "The statement has been terminated.".
An OLE DB record is available. Source: "Microsoft OLE DB Provider for SQL Server" Hresult: 0x80004005 Description: "Violation of PRIMARY KEY constraint 'PK__tbl_AICC__3214EC07D26FCB1E'. Cannot insert duplicate key in object 'dbo.tbl_AICC_Results'. The duplicate key value is (1).".
(SQL Server Import and Export Wizard)
I tried checking off "delete rows in table" I tried checking "delete and recreate tables", then I get a cannot truncate because the table is a foreign key, but I disabled all of the constraints using this:
EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
for those suggesting backup...It is not listed as an option:
That database is hosted on Azure, so I am not sure if that is why I cannot do a backup and restore.
because I was getting "cannot insert into read only Id", I am not getting that anymore so I could only assume that the removal worked. Any assistance is greatly appreciated.
If I am reading this correctly - you want to move/copy from your remote Azure SQL Database to a local instance. If so, then you need to create a BACPAC in Azure, copy that locally and use that for your local system.
See these documents:
https://learn.microsoft.com/en-us/sql/relational-databases/data-tier-applications/export-a-data-tier-application?view=sql-server-ver15
https://learn.microsoft.com/en-us/azure/azure-sql/database/database-export
https://learn.microsoft.com/en-us/sql/relational-databases/data-tier-applications/import-a-bacpac-file-to-create-a-new-user-database?view=sql-server-ver15

SSIS - Cannot insert duplicate key in object 'dbo.FACT_TABLE'

I know that we can't have duplicate records in Fact Table but I'm very new in SQL Integration Services and I'm looking for a package that can recognize that if the surrogate keys already exists in fact tables...
In this moment I've this package:
Each lookup objects get the business key of each dimension in my datawarehouse.
At the first time it run very well because in Fact Table I don't have records, but next I made the test and I run the same data again (because in future I want to run this package every 10 minutes so it will get the same data ofentimes) and I get the following error (that I understand very well I want to build an approach to handle this automatically):
[Load into dbo_DimCI [144]] Error: 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 11.0" Hresult: 0x80004005 Description: "The statement has been terminated.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Violation of PRIMARY KEY constraint 'PK_FACT_FACT_TABLE'. Cannot insert duplicate key in object 'dbo.FACT_TABLE'. The duplicate key value is (337, 44, 3, 19, 4682, 12).".
Which objects I need to insert in my package in order to handle this error?
I believe your intention is to load only the deltas in each load.
Which means if a record already exists in the fact table, then the record should not be inserted again.
You could achieve this by using a Merge Query.
I do not have an example to load a fact table, but I can point you to an example of a post that talks about loading a Type 2 Dim Table.
Check this link:https://www.mssqltips.com/sqlservertip/2883/using-the-sql-server-merge-statement-to-process-type-2-slowly-changing-dimensions/
You should be able to use such a statement in your SSIS package to update your fact table.
Happy to answer any further questions.
Cheers
Nithin

How to transfer data from a text file into the database

I have data from sysssislog table in notepad (.txt) file, and I need to transfer data into the SQL server database.
I made table in sql server. Data should be to transfer in table using SSIS packages. During the work appeared to me this error.
Does anyone know how to solve it? Thanks a lot
[OLE DB Destination [113]] Error: 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 11.0" Hresult: 0x80004005 Description: "Violation of PRIMARY KEY constraint 'PK__sysssisl__3213E83F530E2571'. Cannot insert duplicate key in object 'dbo.sysssislog'. The duplicate key value is (0).".
[OLE DB Destination [113]] Error: SSIS Error Code
DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "OLE DB Destination.Inputs[OLE DB Destination Input]" failed because error code 0xC020907B occurred, and the error row disposition on "OLE DB Destination.Inputs[OLE DB Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "OLE DB Destination" (113) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (126).
The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
[Flat File Source [56]] Error: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on Flat File Source which returns error code 0xC02020C4. The component returned a failure code when the pipeline engine called PrimeOutput().
The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.
SSIS messages can be confusing at times because it looks like there are more errors than there really are. In this case, the first error is key: Violation of PRIMARY KEY constraint All of the others after it are letting you know there was at least one error preventing the task from completing.
Check your mapping and ensure that you're not entering duplicate values into whatever Primary Key you've set for the table.
You can Use BCP to Import your data into SQL Server database:
Here is a simple command for importing data from file:
C:\example.txt into table dbo.example.
bcp dbo.example in 'C:\example.txt' -T -SserverName\instanceName

SSIS 2008 R2 Completes But Gives Error "Violation of PRIMARY KEY constraint"

I've found a number of links on this but so far not the one with an answer.
Issue: SSIS 2008 R2 package importing data from many tables (about 160) of SQL 2000 database (conversion project) into new structures. This has run cleanly a number of times. To be clear, the data appears to be actually importing correctly. However, the last 3 times, I've run into this error. The Task (54) Source (269) shown in the message below is the last step and item in the step.
I've confirmed that the table mention as a "duplicate key violation" actually has the same 49166 records as the source. It seems like it almost just has issue with threading or the time that has elapsed (long running query). I have TRUNCATED the 5 tables in the final step and re-run that single Task 54 and it completes just fine, all green.
It would be good to not have to go hunting through the process due to red herrings. Any idea on how to address this so it reports cleanly?
Thanks
Error message below:
Executed as user: [masked]. Microsoft (R) SQL Server Execute Package Utility Version 10.50.6000.34 for 64-bit Copyright (C) Microsoft Corporation 2010. All rights reserved. Started: 4:36:46 PM Error: 2015-05-20 16:36:48.49 Code: 0xC0016016 Source: Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available. End Error Error: 2015-05-20 16:36:48.50 Code: 0xC0016016 Source: Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available. End Error Error: 2015-05-20 17:19:33.78 Code: 0xC0202009 Source: Data Flow Task 54 Destination 269 - cadNotificationStatus [396] Description: 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__cadNotif__25843E4F1B0907CE'. Cannot insert duplicate key in object 'dbo.cadNotificationStatus'. The duplicate key value is (4, 2).". End Error Error: 2015-05-20 17:19:33.79 Code: 0xC0209029 Source: Data Flow Task 54 Destination 269 - cadNotificationStatus [396] Description: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "input "OLE DB Destination Input" (409)" failed because error code 0xC020907B occurred, and the error row disposition on "input "OLE DB Destination Input" (409)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure. End Error Error: 2015-05-20 17:19:33.79 Code: 0xC0047022 Source: Data Flow Task 54 SSIS.Pipeline Description: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Destination 269 - cadNotificationStatus" (396) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (409). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure. End Error Error: 2015-05-20 17:19:33.81 Code: 0xC02020C4 Source: Data Flow Task 54 Source 269 - cadNotificationStatus [218] Description: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020. End Error Error: 2015-05-20 17:19:33.81 Code: 0xC0047038 Source: Data Flow Task 54 SSIS.Pipeline Description: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "Source 269 - cadNotificationStatus" (218) returned error code 0xC02020C4. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure. End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 4:36:46 PM Finished: 5:19:34 PM Elapsed: 2568.01 seconds. The package execution failed. The step failed.
As per the error, it is failing while to inserting duplicate records in 'dbo.cadNotificationStatus' table. Is there any logic to import only new records from source table which is in SQL 2000, which are not present in destination table? If no, data flow task importing data into this table is going to fail.
It looks like, it is running successfully because you are truncating the table and then importing the whole data again. If you can provide more info regarding source query, it will be more clear.
Just to be 100% sure I would redirect rows to a flat file that are causing you the issue. This will allow you to see what line item is causing the failure or triggering the error message. This link shows a good tutorial of how to do that:
http://www.techbrothersit.com/2013/07/ssis-how-to-redirect-invalid-rows-from.html
Also it looks like you have more going on in your error output from a security perspective based on the below:
Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information.
My guess is that someone else created this package and used: "EncryptSensitiveWithUserKey"...
I would recommend:
While importing the package to SQL Server choose Protection Level: Either
1- Don't save sensitive data.
Or
2- Rely on Server Storage and roles for access control.

Error while importing into table in SQL Server 2008 R2 from Excel File

I am getting this error while importing from an Excel file into a table in SQL Server 2008 R2.
I have added a picture.
Copying to [dbo].[MultiPLU] (Error) Messages 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: "Cannot insert the value NULL into column 'PLUCode', table 'AR4UWin.dbo.MultiPLU'; column does not allow nulls. INSERT fails.".
(SQL Server Import and Export Wizard)
Error 0xc0209029: Data Flow Task 1: SSIS Error Code
DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "input "Destination Input"
(57)" failed because error code 0xC020907B occurred, and the error row
disposition on "input "Destination Input" (57)" specifies failure on
error. An error occurred on the specified object of the specified
component. There may be error messages posted before this with more
information about the failure.
(SQL Server Import and Export Wizard)
Error 0xc0047022: Data Flow Task 1: SSIS Error Code
DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component
"Destination - MultiPLU" (44) failed with error code 0xC0209029 while
processing input "Destination Input" (57). The identified component
returned an error from the ProcessInput method. The error is specific
to the component, but the error is fatal and will cause the Data Flow
task to stop running. There may be error messages posted before this
with more information about the failure.
(SQL Server Import and Export Wizard)
The import process requires a value for every row in the 'PLUCode' column, whereas I believe that your excel spreadsheet sometimes has no value in these cells.
Right clicking on the PLUCode and setting it to allow nulls will allow you to upload the table. The query below will give you the errored entries for review.
SELECT *
FROM Tablename
WHERE PLUCode IS NULL
If you're dealing with duplicates I would recommend a self join to only give you the unique rows. (You'll need a few 'if' statements to check for rows with null values so you don't delete a whole record and leave you with the broken one.) I would be exceptionally careful with using any predefined remove duplicates function (like in excel) unless you've scrutinized the table to ensure it wont drop the completed rows.
EDIT: To respond the need to save as a flat file you'll want to save as a comma delimited csv file. Its in the usual file formats list unless you're using excel 2010, the itll be under the "Save and Send" option.

Resources