【问题标题】:SQL Server 2012 SSIS Script Task for sending mail from Gamil to Gmail , showing "DTS Script :Runtime Error"用于将邮件从 Gmail 发送到 Gmail 的 SQL Server 2012 SSIS 脚本任务,显示“DTS 脚本:运行时错误”
【发布时间】:2015-11-11 02:56:51
【问题描述】:

我正在使用 SSIS 12、SQL Server 2012、Visual Studio 2012 和 .net 4。

我的 SSIS 脚本任务代码(用于发送邮件):

// 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("raihanuahmed@gmail.com", "password");

            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("raihanuahmed@gmail.com");
            msg.To.Add(new MailAddress("raihan.csse.aiub@gmail.com"));
            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
        };
    }
} 

执行此电子邮件发送脚本后,我总是收到

“DTS 脚本:运行时错误”

在 System.RuntimeMethodHandle.InvokeMethod(对象目标,对象 [] 参数、签名 sig、布尔构造函数)
在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(对象 obj, Object[] 参数,Object[] 参数)
在 System.Reflection.RuntimeMethodInfo.Invoke(对象 obj,BindingFlags invokeAttr、Binder binder、Object[] 参数、CultureInfo 文化)
在 System.RuntimeType.InvokeMember(字符串名称,BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] 修饰符、CultureInfo 文化、String[] 命名参数)
在 Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

我已将我的问题上传到 Youtube,这是链接:

DTS Script :Runtime Error

这是我在 Dropbox 中的项目链接:

EmailScript

【问题讨论】:

  • 注释掉smtp.Send(msg);。您仍然收到错误消息吗?
  • 这里描述了如何设置断点:msdn.microsoft.com/en-AU/library/ms140033(v=sql.110).aspx你需要设置一个断点,单步执行代码并找到一个更有用的错误。 “运行时错误”没有用,但如果您在运行时捕获错误,通常可以深入研究并得到有用的错误。
  • 天啊!!!! ,, 如果我注释掉 smtp.Send(msg); ,, 我没有收到任何错误...但是我的问题还没有解决,因为我无法接收到消息
  • 警告:0x0 在任务成功电子邮件:无法附加 VSTA 调试器。重新启动调试可能会解决问题。错误:任务成功电子邮件中的 0x1:调用目标已引发异常。任务失败:任务成功电子邮件
  • 您需要更详细的错误消息,但看起来调试无济于事。取消注释 smtp.Send(msg); 并在其后添加:catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }。如果这是有效代码(不确定),它应该会弹出更详细的错误消息

标签: sql-server email ssis ssis-2012 script-task


【解决方案1】:

我找到了解决方案 :) 非常感谢 Mr.Nick.McDermaid ...... 解决办法是:

更改不太安全的应用程序的帐户访问权限https://support.google.com/accounts/answer/6010255

【讨论】:

  • try/catch 只是为了得到一个更有用的错误。你需要在部署你的包之前把它拿出来,否则它会弹出消息框并冻结。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-13
  • 1970-01-01
  • 2021-10-31
  • 1970-01-01
  • 2015-01-16
  • 2015-09-24
  • 1970-01-01
相关资源
最近更新 更多