【问题标题】:SSIS script task error messageSSIS 脚本任务错误信息
【发布时间】:2015-12-22 15:10:58
【问题描述】:

我在运行SSIS 包时收到以下错误消息。脚本任务使用Microsoft Visual C# 2008。你能帮我解决这个问题吗?

非常感谢!我还附上了错误信息:

Error: 2015-12-22 02:58:08.28
   Code: 0x00000001
   Source: Script Task 
   Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
   at System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp)
   at System.Windows.Forms.MessageBox.Show(String text)
   at ST_d27b216cd7d64713b54c81f6ac28d805.csproj.ScriptMain.Main()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   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 System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
End Error
DTExec: The package execution returned DTSER_FAILURE (1).

C#代码:

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

namespace ST_d27b216cd7d64713b54c81f6ac28d805.csproj
{
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {

        #region VSTA generated code
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

        public void Main()
        {
            // TODO: Add your code here
            System.IO.FileInfo fi;
            String FilePath = null;

            DateTime ModifiedTime = (DateTime)Dts.Variables["File_Modified"].Value;


            DateTime LoadDate = (DateTime)Dts.Variables["File_Last_Load_Date"].Value;

            Dts.Variables["isModified"].Value = false;


            FilePath = Dts.Variables["SourceFolder"].Value.ToString();
            ModifiedTime = System.IO.File.GetLastWriteTime(FilePath);

            Dts.Variables["File_Modified"].Value = ModifiedTime; 
            // fi.LastWriteTime;
            int result = DateTime.Compare(ModifiedTime, LoadDate);

            if (result > 0)
            {
                  MessageBox.Show("File Modified after last load in staging");
                Dts.Variables["isModified"].Value = true;
            }
            else
            {
               MessageBox.Show("file is not modified since last load");
                Dts.Variables["isModified"].Value = false;
            }

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

【问题讨论】:

    标签: c# .net sql-server ssis


    【解决方案1】:

    从您的堆栈跟踪中提取的错误消息是:

    当应用程序未在 UserInteractive 模式下运行时显示模式对话框或表单不是有效操作。指定 ServiceNotification 或 DefaultDesktopOnly 样式以显示来自服务应用程序的通知。

    您必须记住,尽管在调试 SSIS 包时,您有一个不错的 UI(BIDS 或 SQL Server Tools 外壳,具体取决于您的环境),但实际上它并不是为具有 UI 而设计的。当这个包被部署到服务器并被 SQL 作业调用时,你期望会发生什么?即消息框将显示在哪里?谁会单击“确定”以允许线程恢复?

    如果您想发布反馈,您可能只想fire an information event,例如:

    bool fireAgain = false;
    Dts.Events.FireInformation(0, "Script Task", "File Modified after last load in staging", String.Empty, 0, ref fireAgain);
    

    【讨论】:

    • 非常感谢您的帮助,GarethD!我将删除两行 messageBox.Show() 因为代码称为 SQL 作业。我认为这足以解决问题。
    【解决方案2】:

    引发错误是因为您的脚本任务尝试显示消息框并在应用程序未在 UserInteractive 模式下运行时显示模式对话框或表单不是有效操作。因此,如果您想输出一条消息,您可以改用Dts.Log,有关详细信息,请参阅MSDN 文档。

    【讨论】:

    • 非常感谢您的帮助,Jaco!我将删除两行 messageBox.Show() 因为代码称为 SQL 作业。我认为这足以解决问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    • 2022-01-08
    • 2017-06-08
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多