Setting the argument parameters for Dts.Events.FireCustomEvent
Hi all, I am trying to fire a custom event from a script task (C#). The event name is OnError and i get theses errors when i run the package. The type of the value being assigned to variable "System::ErrorCode" differs from the current variable type. The type of the value being assigned to variable "System::ErrorDescription" differs from the current variable type. The type of the value being assigned to variable "System::Cancel" differs from the current variable type. I have been trying to find how to set the argument parameter for this case but to no avail, anyone could help me on this? Here is the code that fires the custom event: private void FireMessage(string content, string eventName) { if (!string.IsNullOrEmpty(content)) { bool repeteEvent = false; object[] obj = new object[1] { content }; Dts.Events.FireCustomEvent(eventName, "Error: " + eventName, ref obj, "Error", ref repeteEvent); } }
April 20th, 2011 9:49am

Did you try adding code to lock the variable first (before consuming it)?Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
April 20th, 2011 10:04am

I'm sorry ArthurZ but i don't understand what you mean.
April 21st, 2011 7:25am

What does your RegisterEvents method call look like? Talk to me now on
Free Windows Admin Tool Kit Click here and download it now
April 21st, 2011 5:40pm

If you mean in the C# script, i don't have a RegisterEvents
April 25th, 2011 7:21am

I'm sorry ArthurZ but i don't understand what you mean. I just remember fixing something like what you experienced by locking / unlocking a variable. I used code public void Main() { Variables vars = null ; bool fireAgain = true; Dts.VariableDispenser.LockOneForRead("varName", ref vars); //Do something with the value... vars.Unlock(); Dts.TaskResult = (int)ScriptResults.Success;} to do so in the Script Task similar to what mentioned in this article: http://sqlblog.com/blogs/jamie_thomson/archive/2010/07/29/using-lockoneforread-with-c-ssis.aspx Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
April 25th, 2011 9:10am

If you mean in the C# script, i don't have a RegisterEvents Exactly. FireCustomEvent first requires you to set up what a "custom event" is... through RegisterEvents. However you got the information to try to use FireCustomEvent, it was misleading - because you're not developing a custom component where you might want to do that. What exactly are you attempting to accomplish in the above code snippet? Report an error? Report a warning? Merely write something to the log? I'm going to assume you just want a message to be delivered to the Output window and/or Log. If that's the case, you should look at FireWarning and FireInformation instead of FireCustomEvent. Talk to me now on
April 25th, 2011 11:40am

What i am trying to do is to get the eventhandler OnError to send an email. I tried using FireError but that stops the sequence but the sequence needs to continu as the error that is sent via email is actually an error in the buissnes logic not the script itself. If i receive an error email, i can go and look at what happend and deal with it manually. I use to have this in VB that worked in a script task Dts.Events().FireCustomEvent(eventName, "Read Service answer fired: " + eventName, New Object(1) {0, content}, "Read Service answer", False)
Free Windows Admin Tool Kit Click here and download it now
April 25th, 2011 1:04pm

You can't use an OnError event to handle an error... that you don't want to be an error. Your only way to get around that would be to muck with the MaximumErrorCount properties, but I don't like doing that. The way I tend to send emails when it's not a fatal issue (which you say this isn't) is to fill some variables (within a script or Data Flow) then use conditional constraints in the Control Flow to send the mail or not. Is that a possibility for you? Talk to me now on
April 25th, 2011 8:20pm

The way I tend to send emails when it's not a fatal issue (which you say this isn't) is to fill some variables (within a script or Data Flow) then use conditional constraints in the Control Flow to send the mail or not. Is that a possibility for you? This could be a possibility that actually makes allot of sense and would actually be easier to maintain then having an email task hidden somewhere and you send time searching for it when you need to change it..... I'll change my code to your suggestion, thank you.
Free Windows Admin Tool Kit Click here and download it now
April 26th, 2011 2:24pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics