Error in C# script task in SSIS when running code for email (POP3) -


i have email script task attempting use pass variables through ssis script task. have made sure spelled right , code compiles. error:

exception has been thrown target of invocation. @ system.runtimemethodhandle.invokemethod(object target, object[] arguments, signature sig, boolean constructor) @ system.reflection.runtimemethodinfo.unsafeinvokeinternal(object obj, object[] parameters, object[] arguments) @ system.reflection.runtimemethodinfo.invoke(object obj, bindingflags invokeattr, binder binder, object[] parameters, cultureinfo culture) @ system.runtimetype.invokemember(string name, bindingflags bindingflags, binder binder, object target, object[] providedargs, parametermodifier[] modifiers, cultureinfo culture, string[] namedparams) @ microsoft.sqlserver.dts.tasks.scripttask.vstataskscriptingengine.executescript()

i admit being newbie here, , apologize if there easy solution.

i have added following 2 namespaces:

using system.net; using system.net.mail; 

in code below, hard coding username , password credentials. can change variable (i think.)

when hard code values variables directly in code, still gives same error. code builds , cleans fine, assistance appreciated. thank you.

public void main()     {         // todo: add code here         {              string sendmailto = dts.variables["sendmailto"].value.tostring();             string sendmailfrom = dts.variables["sendmailfrom"].value.tostring();             string ssubject = dts.variables["ssubject"].value.tostring();             string sbody = dts.variables["sbody"].value.tostring();             string smtpserver = dts.variables["smtpserver"].value.tostring();                  sendmailmessage(sendmailto, sendmailfrom, ssubject, sbody, false, smtpserver);              dts.taskresult = (int)scriptresults.success;          }     }     private void sendmailmessage(string sendto, string from, string subject, string body, bool isbodyhtml, string server)     {          mailmessage htmlmessage;         smtpclient mysmtpclient;          htmlmessage = new mailmessage(sendto, from, subject, body);         htmlmessage.isbodyhtml = isbodyhtml;          mysmtpclient = new smtpclient(server);         mysmtpclient.credentials = new system.net.networkcredential("myusername", "mypassword"); ;         mysmtpclient.send(htmlmessage);      }      }      #region scriptresults declaration     /// <summary>     /// enum provides convenient shorthand within scope of class setting     /// result of script.     ///      /// code generated automatically.     /// </summary>     enum scriptresults     {         success = microsoft.sqlserver.dts.runtime.dtsexecresult.success,         failure = microsoft.sqlserver.dts.runtime.dtsexecresult.failure     };     #endregion  } 

rookie mistake! code didn't work in regular c# console. debugged there, made necessary adjustments, , presto! apologies spam.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -