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

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

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

Loading temporary tables in parallel

I load data from one SQL Server A to temporary table via Execute SQL Task (select * into x from remote_server) and join with another remote SQL Server B in Data flow.
So I have two source in Data Flow:
1.Local temporary table which contains date from SQL Server A (loaded in previous task)
2.Table on remote SQL Server B.
To achieve it I change "RetainSameConnection" connection manager property (which I use it to pull data from SQL Server A to local machine (SSIS server) to TRUE. It works but I cannot load these tasks parallely, because I get:
S [[209]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error
has occurred. Error code: 0x80040E14. An OLE DB record is available.
Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E14
Description: "Statement(s) could not be prepared.". An OLE DB record
is available. Source: "Microsoft SQL Server Native Client 11.0"
Hresult: 0x80040E14 Description: "Invalid object name
'##V_DEL'.".
[SSIS.Pipeline] Error: "S" failed validation and returned validation
status "VS_ISBROKEN".
How to solve it?
If you are using RetainConnection = True then only 1 object at a time can have the retained connection. This means that if 2 sql tasks run in parallel then only 1 will use the retained connection. Similar to the issue that you cant have a lookup and a dest with the same retained connection.
The only workaround is to serialize your SQL calls.
Simple solution: Just take Global temp table creation task in one sequence container and insert part in another sequence container. It will work fine and we can run the 2 task in parallel.
Take temp table creation part in one sequence container and insert part in another sequence container and it will work even if we run task in parallel having more than one Global temp tables.

SQL Server : Statement Conflict

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

SSIS - Intermittent error "Conversion failed because the data value overflowed the specified type."

I have an SSIS package which intermittently fails with a handful of errors, the two most informative of which are:
DFT_PlaySummary
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: "Invalid date format".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Invalid date format".**
DFT_PlaySummary
There was an error with input column "dtCreated" (2129) on input "OLE DB Destination Input" (2121). The column status returned was: "Conversion failed because the data value overflowed the specified type.".**
Both source and destination DB's are SQL Server 2008 R2. The column dtCreated in both source and destination is DATETIME (NOT NULL).
Now, I understand the basis of what the error message is saying, but I can't understand how the data or the conversion could be invalid in the package without having already been deemed invalid at the source.
Strangely, on some days the package will fail with this error, restart itself (as per the package settings) and then succeed without any manual intervention.
Any pointers as to what I should be looking for within the package steps that could be causing this? The data flow task itself consists of a couple of OLE DB sources, each with a derived column, followed by a merge of these data sets and then a conditional split to various OLE DB destinations depending on the dtCompleted value.
Two options you can try,
Use Data Conversion in Data flow task to convert necessary values.
Set specific data types in derived column itself, if your column is available there.
Data conversion is handy when this type of error occurs commonly.
SSIS date time format should be used correctly. The below article explanins difference clearly. Use the correct format, which is required for you.
http://consultingblogs.emc.com/jamiethomson/archive/2005/11/15/SSIS_3A00_-What_2700_s-the-difference-between-DT_5F00_DATE-and-DT_5F00_DBTIMESTAMP.aspx

SSIS Connection to ORACLE (Multiple-step OLE DB operation generated errors)

I have an "Native OLE DB\Oracle Provider for OLEDB" connection in SSIS package to execute a procedure on ORACLE.
Procedure is working fine but in log file I am seeing below mentioned warning, which is slowing down the execution.
Warning : Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
The procedure is having 5 inputs and 2 out paras. After reading few articles which point says it could be due to data type/size mismatch.
I personally think its something to do with connection setting. I created a simple task of deleting data from a table without any para or variable. Still there was a warning
Its simple delete statement.
BEGIN DELETE FROM KC.KC_PAYMENT; END;
The warning appears after "validation is completed". and before the delete statement "Progress" event.
Deepak
There are many ways to work around this problem. What I am thinking as of now is
1) Store the Connection string that points to oracle into sql server table or in variable.
https://www.connectionstrings.com/oracle-provider-for-ole-db-oraoledb/
2) Check for security while fetching the records.
3) Use the "Oracle provider for OLE DB" from SSIS, don't use the "Microsoft Provider for Oracle" because a 64 bit version of it does not exist.
4) Schedule your packages with the SQLAgent.

Resources