A common misconception in SSIS is that an error is a single event. The reality is that an error is actually a collection, but how many errors are in an error? To demonstrate this consider the following statement: USE tempdb ; GO IF EXISTS( SELECT * FROM sys.tables WHERE name = ‘pkerror’ ) BEGIN DROP TABLE pkerror END CREATE TABLE pkerror ( col1 INT PRIMARY KEY ); GO INSERT pkerror SELECT 1 AS pkey UNION ALL SELECT 1 AS pkey Executing this code in SQL Server Management Studio results in a single error for a primary key violation: But attempt this within an SSIS package and the outcome is a bit different. Using a data flow task with a query source I will replicate this same query logic and error(s). To display the error information use a script task on the DuplicateKey data flow task that will display ErrorCode, ErrorDescription , and a user defined variable called ErrorCount , data type integer: The code is in VB.NET: Public Sub Main () Dts.Variables ( “ErrorCount” ) .Value + = 1 MessageBox.Show ( “Error Count: ” + Dts.Variables ( “ErrorCount” ) .Value.ToString ()) MessageBox.Show ( “Error Code: ” + Dts.Variables ( “ErrorCode” ) .Value.ToString + ” Error Desc: ” & amp ; _ Dts.Variables ( “ErrorDescription” ) .Value.ToString ()) Dts.TaskResult = ScriptResults.Success End Sub Executing the package results in the following message boxes being displayed: This truly is a single error, but if you compare the error descriptions and codes you will notice that they are all different. The first error is returning what was caught from the Microsoft SQL Native Client and provides the most relevant information to the underlying cause, similar to what is displayed in SSMS. The next two errors are specific to SSIS and provide information about the error handled at the data destination component, pkeyError Table, and the specific events.
↧