1
votes

I am using SSIS 12, SQL Server 2012, Visual Studio 2012 and .net 4.

My SSIS script task code(for sending mail):

// Introduction to the script task
/* The Script Task allows you to perform virtually any operation that can be accomplished in
 * a .Net application within the context of an Integration Services control flow. 
 * 
 * Expand the other regions which have "Help" prefixes for examples of specific ways to use
 * Integration Services features within this script task. */

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;

namespace ST_20fdf0b00e2949fda158e6680c127473
{
        public void Main()
        {
            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential("[email protected]", "password");

            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("[email protected]");
            msg.To.Add(new MailAddress("[email protected]"));
            msg.Subject = "AW2012 ETL Process Complite";
            msg.Body = string.Format("{0} records loaded into DimProduct", 0);

            smtp.Send(msg);

            Dts.TaskResult = (int)ScriptResults.Success;
        }

        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
    }
} 

After executing this email sending script, I am always getting

"DTS Script :Runtime Error"

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

I have uploaded my problem into Youtube here is the link:

DTS Script :Runtime Error

Here is my project link in Dropbox:

EmailScript

1
comment out smtp.Send(msg);. Do you still get the error?Nick.McDermaid
This describes how to set a breakpoint: msdn.microsoft.com/en-AU/library/ms140033(v=sql.110).aspx you need to set a breakpoint, step through the code and find a more useful error. "Runtime error" is not useful but if you capture the error while it's running you can usually drill in and get a useful error.Nick.McDermaid
OMG !!!! ,, if i comment out smtp.Send(msg); ,, I do not get any error ... But my problem isn't fixed yet as i cant able to receive the messageRU Ahmed
Warning: 0x0 at Task Succesful Email: Cannot attach the VSTA debugger. Re-starting the debugging may resolve the problem. Error: 0x1 at Task Succesful Email: Exception has been thrown by the target of an invocation. Task failed: Task Succesful EmailRU Ahmed
You need a more detailed error message but it looks like debugging won't help. Uncomment smtp.Send(msg); and add this after it: catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }. If this is valid code (not sure) it should pop up a more detailed error messageNick.McDermaid

1 Answers

2
votes

I have found the solution :) Many Many thanks to Mr.Nick.McDermaid ...... solution is :

Change account access for less secure apps https://support.google.com/accounts/answer/6010255