sendmail - Calling Email OnError from ScriptTask of SSIS -


i have simple ssis package single script task on it. have onerror event send mail task.

all i'm doing testing see if can send email when detect error withing script. variable use hold error message email causes error.

"a deadlock detected while trying lock variable "user::errmsg" read access. "

here simple script

public void main()         {             try             {                 int x = 2;                 if (x ==2)                 {                     throw new exception("the number  2");                 }                  dts.taskresult = (int)scriptresults.success;             }              catch(exception e)             {                 dts.variables["errmsg"].value = e.message;                 dts.events.fireerror(-1, "here", "my error", "", 0);                 dts.taskresult = (int)scriptresults.failure;             } 

how can pass message send email when error occurs in script task ?

ssis variables locked , relased in post execute event .in case errmsg variable gets locked script task , same time variable accessed in on error event sendmail component creating deadlock situation .you need unlock variable before accessed other components during execution phase.

try :-

 catch (exception e)         {             variables lockedvariables = null;             dts.variabledispenser.lockoneforwrite("errmsg", ref lockedvariables);             lockedvariables["errmsg"].value = e.message;             lockedvariables.unlock();               dts.events.fireerror(-1, "here", "my error", "", 0);             dts.taskresult = (int)scriptresults.failure;          } 

this ensure before error occurs ,the variable unlocked , can accessed in execution events such on error or onexecstatuschanged.

more on how handle these type of deadlocks explained todd mcdermid in blog


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -