Script Task Raising OnError Events
Oct 11, 2005Is there a way I can stop a script task of a control flow from raising OnError Events? or Is there a way I can Set Dts.Results to Fail without having the script task raise OnError event.
View 8 RepliesIs there a way I can stop a script task of a control flow from raising OnError Events? or Is there a way I can Set Dts.Results to Fail without having the script task raise OnError event.
View 8 RepliesI'm very new to using SSIS. I have a large number of SQL databases (archived .mdf/.ldf files) with data that needs to be imported into one giant database. My problem is that half of the databases are missing a column that was introduced in a newer version of the database schema and when my package executes my data flow task it errors out. I basically get a message stating that it cannot prepare any statements because the SQL command that I am using is trying to select column data from a column that doesn't exist.
I figured that I could set the OLEDB Source inside of my Data Flow to have a Data Access Mode = SQL command from variable. The variable bound to the component is called "MySelectQuery" and is initially set to my "new format" query. From there I could create an event handler for the OnError event of the Data Flow Task, switch value of "MySelectQuery" to equal the "old format" query and rerun the Data Flow Task.
I'm not sure how to accomplish restarting my Data Flow Task after changing "MySelectQuery" in the OnError event. I just tried setting up the package to use CheckPoints but it doesn't seem to be working right for me. When I restart the package it starts over even though there is a checkpoint file that seems to have captured the state after the failure.
Any ideas?
--Paul
Greetings,
We have a package that runs on 3 servers, all based in different countries and time zones. Each package does logging to a common SQL Server based in New York. (We log to the same server to make monitoring of the package run results easier.) We expect that our overseas servers will occassionally fail to make a database connection and have coded a Try/Catch block in our Script task to ignore errors that occur when attempting the SQL Server logging.
The problem is that the OnError event handler defined at the package level is being called whenever a server fails to make a database connection. The Catch block appears to not be called at all. I've included below the short method that does the SQL Server logging. The "Dts.Log" line logs to a SQL Server and usually works. However, when it fails, the "WriteEventLogEntry" method is supposed to be called to write an error to the server's event log. (I haven't included the "WriteEventLogEntry" code but it works fine when called elsewhere in the package to do our non-error event logging.)
Public Sub WriteSqlServerLogEntry(ByVal logMessage As String, ByVal dataCode As Integer, ByVal dataBytes() As Byte, ByVal rowsInserted As Integer)
Try
Dts.Log(logMessage, dataCode, dataBytes)
Catch ex As Exception
WriteEventLogEntry("An exception was thrown while attempting to log the following message to the SQL Server provider: " + logMessage, EventLogEntryType.Error, rowsInserted)
End Try
End Sub
Shouldn't a Catch block prevent the OnError event from being raised? How can I change my package to ignore all errors that occur when attempting SQL Server logging?
Gracias!
BCB
Does anyone know how to create an eventhandler for a dataflow task specific events (OnPipelinePostEndOfRowset, OnPipelineRowsSent, etc.)? These events are available for logging via the standard logging infrastructure, but there seems to no eventhandler for them.
The reason I'm interested is that parsing information logged by these events using builtin log providers is not easy (eg., the number of rows sent gets burried somewhere in the message column (i'm using sql provider). I'd like to capture this information and record it cleanly in a custom ssis metadata database i'm building. Any ideas are welcome. Thanks.
-alex
Hello experts. I have been searching for anything about this but found very little. What are the events logged in SQL Server Error Logs aside from Successful/Failed Login, Backup/Restore/Recover database and, start/init sql server? Can we configure this to log other events, like CREATE or DBCC events for example? If so, how? Thanks a lot.
View 1 Replies View RelatedI have a start date, end date for each event.
I want to list all events between the start and end date comes in Saturday or Sunday.
in SQL server 2005 TSQL statement.
any insights ?
I am using this code for LongRunning Queries.
CREATE EVENT SESSION LongRunningQuery
ON SERVER
ADD EVENT sqlserver.sql_statement_completed
(
ACTION (sqlserver.sql_text, sqlserver.tsql_stack)
WHERE sqlserver.sql_statement_completed.duration > 60000
[Code] ...
Here Instead of writing to XML file how can send an EMAIL if a query runs more than 1 minute in my server ?
I want to raise the custom success message after insert and update something like say 5 records updated successfully or inserted successfully?Is there a way i can do that in stored procedure?Also,can someone enlighten me on 'ReturnValue' part of [ ParameterDirection.ReturnValue;]here.
I am coding in c# ,(sql server 2005)and my insert and update codes are in DAL,which gets called from BLL like this. public int updateRecord(int data1, string text1, string text2, bool ind, string sproc,Label lblErr) {
using (SqlConnection fbConnect = new SqlConnection(appProperty.dbconnect))
{
SqlCommand fbCmd = new SqlCommand(sproc, fbConnect);
fbCmd.CommandType = CommandType.StoredProcedure;
..... parameter stuff......
SqlParameter val = fbCmd.Parameters.Add(new SqlParameter("@ReturnValue", SqlDbType.Int));
val.Direction = ParameterDirection.ReturnValue;
try{
fbConnect.Open();
fbCmd.ExecuteNonQuery();}
catch(Exception ex){lblErr.Text = ex.Message}
int iSuccess = (int)fbCmd.Parameters["@ReturnValue"].Value;//I am NOT using this effectively.How can i make use of it?
return iSuccess;
}
}
Hi,
I am building a custom component. In the Validate() method I am checking for various things. Here's a section of my code:
if (ComponentMetaData.InputCollection[0].InputColumnCollection.Count != 1)
{
return DTSValidationStatus.VS_ISBROKEN;
throw new Exception("You need to select one and only one column");
}
The problem I'm finding is that my Exception never gets thrown so I never see the error in the UI. if I reverse the 2 lines like so:
if (ComponentMetaData.InputCollection[0].InputColumnCollection.Count != 1)
{
throw new Exception("You need to select one and only one column");
return DTSValidationStatus.VS_ISBROKEN;
}
Then I get my error message in the UI but I never get anything returned from my Validate() method - which doesn't seem quite right to me.
I don't like using FireError() either because it merely puts the error into the Task list window - and who ever looks at the Task list window???
I'm basically just after some guidance about what people think is the "proper" way of doing this. At the moment I prefer to throw an exception because that way I get some errors in the UI.
Regards
Jamie
I feel like I'm missing something obvious here, but I'm stumped...I have a stored procedure with code that looks like:INSERT INTO MyTableA ( ...fields... ) VALUES (...values...)IF (@@ERROR <> 0)BEGINROLLBACK TRANSACTION;RAISERROR('An error occurred in the stored proc.', 16, 1);RETURN(1);END--FORCING AN ERROR AT THE END FOR TESTING PURPOSESRAISERROR('Proc Successful',16,1)On MyTableA, there is a trigger that loops through the inserted data andstops the insert in certain circumstances, returning an error:IF (some criteria)BEGINROLLBACKRAISERROR('An error occurred in the trigger.',16,1)RETURNENDWhen I call the stored procedure from VB (connecting via RDO) witherror-causing data, the trigger successfully stops the insert, and adds thetrigger-error-msg to the errors collection, but it does NOT seem to createan error situation back in the stored procedure. The procedure finishes upwith the "Proc Successful" message, so that when I iterate through theerrors collection back in VB, I have "Proc Successful" followed by "An erroroccurred in the trigger."Is there some way I'm not finding to have the calling procedure recognizethat a raiserror occurred in the trigger and behave appropriately for anerror situation?Jen
View 1 Replies View RelatedWhen a catchable error occurs in a try block, control is passed to theassociated catch block. While I am then able to examine properties ofthe error using such functions as ERROR_NUMBER() in the catch block,the error-logging scheme used in my company requires that the actualerror be raised so that it can be picked up by components in the nexttier. I appear to be unable to do that -- I can raise some other errorthat has all of the properties of the original except the error number.For example, division by zero raises error 8134. If the code thatproduces that error is enclosed in a try block, I seem to be unable toraise that error from the catch block. Of course, if I never used thetry block to begin with this wouldn't be a problem, but then wewouldn't have the advantages of this structure as it applies to othererrors, some of which we may wish to handle differently. WhileTry-Catch looks great as a way of allowing us to handle errors in acustomized way and to avoid having all errors be passed up to ourmiddle tier, it seems that we are unable to pass ANY such errorsforward, and that is a problem for us, too. Is my understanding ofthis situation correct, or is there some way around this problem, e.g.,is there any way I could have raised error 8134, in the above example?Thanks.
View 2 Replies View RelatedHi,I am using sql server 2005 and i am having table with a column which has unique key constraint.So if the user tries to enter the duplicate value for that particular column and try to save it ,it errors out in runtime..how do i raise the user friendly error message in this DB error, when user tries to save it.Thanks
View 9 Replies View RelatedHi everyone,
I have a package setup like this:
PackageA -> ContainerA -> ContainerB -> ExecutePackageTaskA (calls PackageB)
PackageB -> ScriptTaskA
If an error occurs in ScriptTaskA from PackageB, the OnError event handler in PackageA fires once and catches the event from ScriptTaskA; that is, the output of the SourceName system variable is "ScriptTaskA" from PackageB. So far so expected.
Now, the same error is handled differently by PackageA's OnTaskFailed handler. The OnTaskFailed handler fires twice - once for ScriptTaskA and once for ExecutePackageTaskA; that is, two outputs are returned - one for "ScriptTaskA" and the second one for "ExecutePackageTaskA". That's strange to me.
Why does the OnError handler only fire once and the OnTaskFailed twice? Is there a setting that does this?
Thanks in advance,
Langston
Hi
We are generating log file in our SSIS package by enabling the built-in feature of SSIS tool. We are generating log for the "OnError" event. This also recorded the error/failed task messages in the text file "log.txt". That error information is too complex with more unwanted information like below
----------------OnError,,,pkgExtract,,,8/30/2006 11:50:04 AM,8/30/2006 11:50:04 AM,-1071636471,0x,An OLE DB error has occurred. Error code: 0x80040E21.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E21 Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".
OnError,,,pkgExtract,,,8/30/2006 11:50:04 AM,8/30/2006 11:50:04 AM,-1071607780,0x,There was an error with input column "create_user_id" (116) on input "OLE DB Destination Input" (103). The column status returned was: "The value violated the integrity constraints for the column.".
OnError,,,pkgExtract,,,8/30/2006 11:50:04 AM,8/30/2006 11:50:04 AM,-1071607767,0x,The "input "OLE DB Destination Input" (103)" failed because error code 0xC020907D occurred, and the error row disposition on "input "OLE DB Destination Input" (103)" specifies failure on error. An error occurred on the specified object of the specified component.
---------------------------------
This is infact not in a better readable format. We also don't want to do our error logging in database.
Is there any way of defining our error log and create error error log with customization of our messages . Can we do it using OnError event handler.
Please help us with some good solution to avoid giving this confused error log messages.
Thanks
Kumaran
Is the Onerror Event Handler from the tabbed window in the IDE the same as the red arrow paths that can be used in the control flows and Data Flows?
If yes, what and where is the best practice to use?
If not, can you elaborate?
Thanks,
Hi,
I am having a few problems getting the opomum configuring the OnError event hendler for my new package. What im trying to do is log the Error event and sound out an email (which i am achiving) where i am encountering a problem is trying to determin the severity of the error.
What i would like to achive is to send an email and log the error (as i currently do) but if the error has the power to stop the package from executing i would like to fire an additional script to move the loading files to a failed location.
My initial thoughs were to put an expression the on the procdural constraint in he error handeler but i cant find which System variable to apply the logic to.
Anyone any suggestions?
Thanks
Paul
Hi,
The IDtsEvents.OnError method has a boolean return type whereas most of the other methods on that class are voids.
Why does OnError return a boolean?
What is the effect of returning true?
What is the effect of returning false?
Thanks in advance
-Jamie
[Microsoft follow-up]
I am using following script to combine all the System:ErrorDescription on OnError
Dts.VariableDispenser.LockForRead("ErrorCode")
Dts.VariableDispenser.LockForRead("ErrorDescription")
Dts.VariableDispenser.LockForRead("SourceName")
Dts.VariableDispenser.LockOneForWrite("Errordesc", vars)
Dts.VariableDispenser.GetVariables(vars)
errNumber = CType(vars("ErrorCode").Value, Integer)
errDescription = vars("ErrorDescription").Value.ToString()
errSource = vars("SourceName").Value.ToString()
errdesc = vars("Errordesc").Value.ToString()
vars("Errordesc").Value = errdesc + errNumber.ToString() + vbNewLine + vbNewLine + _
errDescription(+vbNewLine + vbNewLine + _
errSource)
Please note that "Errordesc" is the variable which I declared on script as readandwrite variable.
But on execution of this script I get error
Error: A deadlock was detected while trying to lock variables "User::Errordesc" for read/write access. A lock cannot be acquired after 16 attempts. The locks timed out.
any sugestion...
Please note that without ErrorDesc, the script runs successfully
hello all,
im looping on a folder with excel files via a script and a foreach loop, what i need to do is:
while looping if a file generate an error , to store that error in a row in a SQL table and continue with the next file.
any help is appreciated.
Hi guys,
I have a package name "Package1" and I have a few data-flow tasks in it.
whenever anything fails in the "Package1", I want to send out the failed email to alert myself.
So first step, I went to EventHandler tab, and select Executable as "Package1" and Event Handler as "OnError".
and then I added SendMailTask. I manually ran SendMailTask, failed email send to me okay.
But when I run package from Microsoft visual Studio (IDE), the package failed but it doesn't send out failed email.
Error code:
[174]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "xxx" failed with error code 0xC0202009. There may be error messages posted before this with more information on why the AcquireConnection method call failed.
Maybe I misunderstand OnError eventhandler, or I set up it wrong.
Thanks
I have a package which have two sequence container, first container is used to transfer data to a staging area and second sequence container is used to transfer to destination from that staging area. And I also apply transaction required to second sequence container.
There are several execute sql tasks and several data flow tasks inside two sequence container.
first sequence container( 1.execution sql task-> 2.data flow ->3.execution sql task) ->
second sequence container(4.execution sql task-> 5.execution sql task-> 6.data flow-> 7.data flow -> 8.execution sql task-> 9.data flow...)
I create ExecutionLog table which is used to log status for this package on our sql server. First this status field is null, then during this package run , it change to 'in process', and after this package finished, it change to 'success' or 'failure' depending this package can run successfully or not.
This package can be run only if status is 'success' ,'failure' or null. So I need to change this status field during package execution.
For updating package to failure, I need to add event handler to change that status using execute sql task.
First time I perform to execute sql task on onError event handler tab (this event handler is applyed on package level ) .
And for testing envent handler I use old schema version to make sure I get failure for '8 execution sql task'.
But package seems to get stuck at '8 execution sql task' inside second sequence container( always yellow when I run from ssis) and never fire envent handler. '8 execution sql task' is used to update related table.
Second time I remove onError envent handler and change to use on onTaskFailed event handler tab (this event handler is applyed on package level ) .
But everything is the same as using onError event handler except I got error output but still can not fire event.
Why '8.execution sql task' can not fire onError or onTaskFailed?
For this case what kind of event handler I need to use, what kind of level I need to apply for this event handler.
I have included the Send email task and sending email from SSIS package on Error event.
But for an error I am receiving multiple atleast 10-15 email generated. i got only 2 emails with revelant error message and other email gives message like "
Thread "WorkThread1" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown."
I have included ''@[System::ErrorDescription]' as an email attachment.
Is there any way to get only specific relevant error email.
Please suggest
Hi,
I want insert data into table from csv file, so I put a data flow task on control flow tab,
a flat source and a ole db dest on data flow tab. They work well.
Then to get the error log I put a script task on event handler tab, in this script task I want to
output the error description to a txt file while the data flow task fails for any reasons
such as constraint failure etc.
In this script task I think I can get the error description by using property Err.Description,
but Err.Description is empty while data flow task fails.
How can I get the error description in the script task on event handler tab.
thanks!
I used onError event to send email in case ssis pckage fails
but it send multiple email with errordescription. for ex below are the errordescription of four diferent emails i received.
Thread "WorkThread0" has exited with error code 0xC0047039.
An error occurred with the following error message: "The connection "{01AF859A-CF97-4F6C-9C78-1AA4B1C9C27B}" is not found. This error is thrown by Connections collection when the specific connection element is not found.".
Thread "SourceThread0" has exited with error code 0xC0047038.
The PrimeOutput method on component "Flat File Source - Read from source file" (1) returned error code 0xC0202092. 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.
Can anyone suggest if we can combine all this error description and send this as one email.
I have a package the looks for any Excel files in a folder, moves the data to a SQL table, then archives the file to one of two archive folders--a success folder or an error folder. I have an OnError handler on the Data Flow that sets a flag that lets the archive process know where to move the file.
This works when the processing is successful. It also works when the error in the Data Flow occurs right off the bat, i.e., in the Source. When the error occurs later on, say in the Destination, it doesn't work correctly. In this case, the OnError sets the flag, but when the archive process tries to move the Excel file, it can't because it's locked. I assume this is because OnError interrupted the Data Flow before the Excel file could be closed properly.
Any ideas on how I can avoid this problem? Can I manually get the Data Flow to close the Excel connection somehow?
I have a SSIS package which takes excel spreadsheets (exported from MS Project) and imports them into tables in my database. I have each step of my control flow set up with "On Success" so it only continues if the previous step was successful.
My next step is to create a asp.net page and/or web part so that I can have my user click a button to launch this SSIS and import this data. I have seen articles on how this could be done via code - so I assume it can be done. But what I cannot find is how alert the user if an error has occured in the execution of the SSIS.
How can you alert a user that a package you executed though vb.net in the front end errored?
Could I build something in to the OnError handler that returns the error and have that error returned to the front end App??
Any insight/examples for this would be much appreciated.
Thanks.
I would like to AUTOMATICALLY count the event for the month BEFORE today
and
count the events remaining in the month (including those for today).
I can count the events remaining in the month manually with this query (today being March 20):
SELECT Count(EventID) AS [Left for Month],
FROM RECalendar
WHERE
(EventTimeBegin >= DATEADD(DAY, 1, (CONVERT(char(10), GETDATE(), 101)))
AND EventTimeBegin < DATEADD(DAY, 12, (CONVERT(char(10), GETDATE(), 101))))
Could anyone provide me with the correct syntax to count the events for the current month before today
and
to count the events remaining in the month, including today.
Thank you for your assistance in advance.
Joel
Dear All:
I want to ask how can I handle OnError events in stored procedure in MSSQL.
Actually I wanted to place some Rollback procedure on this.
Can you suggest some methods for me?
KEVIN
Hi all,
I have a Script Task in an OnError EventHandler, the Script Task is used to send an Email to notify about the Execution Error. I'm currently using the System:ErrorDescription variable in my Script Task to provide details about the error but I have noticed that the Error Description written in the Windows Event Log when using OnError Logging is much more detailed than the content of the System:ErrorDescription variable. How can I use the same Error Description in my Script Task ?
I'll appreciate any help.
Context: I have a web page that uplaods a file that is then imported to the database via an SSIS package.
Problem: If and when the package encounters an error, I want to surface that error to the user via the web page.
Approach: I derived my own class from the DefaultEvents class and then overrode the OnError event handler to catch any errors raised during package execution. I then pass my class to the package Execute method.
Results: The OnError is triggered, but I don't know how to abort package execution nor how to pass the error context to the user. I tried raising a custom exception in the OnError handler, but it failed to propogate to the calling code (ie the code that executes the package).
Another approach would be to write to a database table and then do a query from my web page after the package is done executing (alternatively, I could generate a log file). Seems like a lot of work though. All I want is to pass the error context back to my calling code so I can tell the user what happened.
Thanks in advance for your help.
I have an SSIS package that contains a For Each Loop Container. I have three Data Flow tasks within the container. I have an OnError event handler associated with the encapsulating container. When one of the Data Flow tasks within the For Each Loop Container fails, the OnError for the Loop Container gets called 5 times. The OnError handler is just a script task that sends a notification email. I am not explicitly Dts.taskresult = failure, nor am I calling FireError.
View 1 Replies View RelatedI'm trying to implement a custom log table. To keep the discussion simple, let's say I only have 1 column in this table and all I want to write in it are
"Start" when the package starts
"Error" when it encounters an error
"Finish" when the package finishes. Even if there was an error, I still want to enter "Finish'.
My Control Flow has 3 task objects, 2 Execute SQL Tasks, and 1 Data Flow Task in between them.
The first Execute SQL Task does an insert statement for the Start and the second Execute SQL Task does an insert for the Finish.
To capture any package errors, I also have an Execute SQL Task (to insert "Error") in the Event Handler for OnError. I see that when I cause an error in my package it can raise multiple OnError events, which will envoke my Execute SQL Task multiple times. (This is good because it will allow me to write a line per error event with the error description.)
The problem I have is, how do I write the "Finish" log when I have an error? If I put the insert for the finish in the same Execute SQL Task with the errors, then it will write a "Finish" for every error. But I can't put it anywhere else because if I put it anywhere else, the package never makes it there because it stops at the OnError Event Handler.
Or is there a way for me to tell the package to do the 2nd Execute SQL Task all the time?
Lastly, is there a better way to do this kind of custom logging?
Hi,
I've setup the option to mail the error to a person. When the option is on I get the error message by mail but the package does not finish (eg. the failing task does not become red and the output windows never says anything about the error) - if I set the option to off the task fails as expected.
Is there something I havn't set up correctly?
Regards
Simon