MessageBox.Show会在服务器端引起超时问题吗? [英] Will MessageBox.Show cause the timeout issue on server side?

查看:65
本文介绍了MessageBox.Show会在服务器端引起超时问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上的SQL Server Agent中有一个计划的SSIS包,其中的script taskscript task.我确实为SQL连接设置了timeout,对于Try块中的某些代码,它会引发错误,并且Catch块中有MessageBox.Show.如果我按原样保留代码,则它将使作业失败,但是如果我注释掉那些MessageBox.Show并将Catch块留空仅用于测试目的,则该作业将成功运行.

I have a scheduled SSIS package with a script task in SQL Server Agent on our server. I did set the timeout for the SQL connection, and for some of the codes inside the Try block, it will throw the error, and there is MessageBox.Show inside the Catch block. If I leave the codes as they are, it will fail the job, but if I comment out those MessageBox.Show and leave the Catch block blank just for testing purpose, the job ran successfully.

有人知道MessageBox.Show会影响timeout在服务器端进行连接,还是在禁用显示错误消息后完全导致此不同结果的原因?

Anybody knows that the MessageBox.Show will affect the timeout for connection on server side or what exactly cause this different result after disable showing the error message?

先谢谢您了:)

推荐答案

在DTS中,您可以创建UI交互,从而导致程序包无限期地等待按钮单击继续.

In DTS, you could create UI interactions that would result in a package waiting indefinitely for a button click to continue.

SSIS通过确定它是否在"互动模式".这与Hadi的答案类似,但不同之处在于,仅在BIDS/SSDT/Visual Studio外部运行SSIS程序包不足以触发取消设置交互模式标志.

SSIS attempts to redress this issue by determining whether it is running in "interactive mode". This is similar to Hadi's answer but different in that running an SSIS package outside of BIDS/SSDT/Visual Studio alone is not sufficient to trigger the interactive mode flag to be unset.

尝试以非交互模式运行的SSIS包与UI进行交互将导致从代码中引发异常.

An attempt to interact with the UI from an SSIS package running in non-interactive mode will result in an Exception being thrown from the code.

如果我要向脚本任务添加消息框,我发现一个有用的模式是将System :: InteractiveMode变量作为ReadOnly变量添加到任务,然后使用以下内容

If I am adding message boxes to a Script Task, I find a helpful pattern is to add the System::InteractiveMode variable as a ReadOnly variable to the Task and then use the following

bool interactiveMode = (bool) Dts.Variables["System::InteractiveMode"].Value;
if (interactiveMode)
{
    // UI code here
    MessageBox.Show("Something happened");
}

我发现上面的代码更干净,因为可以将相同的代码部署到生产环境中,并且也可以在桌面上运行,而不是一切正常,一秒钟,而我进行更改以删除调试垫片".一些本可以做得更好的代码

I find the above to be cleaner in that the same code can be deployed to production and also run on my desktop versus "Everything works and one second while I make changes to remove my debugging shims" ... and fix that little bit of code that could have been done better

最后一点,我还发现使用UI元素的格式不好,因为我很懒,不想截屏或写下他们说的话.而是使用包中的Dts.Events.FireInformation事件.例如,此通用代码将枚举所有变量(我已将其检查为只读或读写)及其值.

As a final bit, I also find that using UI elements bad form because I'm lazy and don't want to have to screenshot or write down what they say. Instead, make use of the Dts.Events.FireInformation event in your package. For example, this generic code will enumerate all the variables (that I've checked as readonly or readwrite) and their values.

    public void Main()
    {
        bool fireAgain = false;
        string message = "{0}::{1} : {2}";
        foreach (var item in Dts.Variables)
        {
            Dts.Events.FireInformation(0, "SCR Echo Back", string.Format(message, item.Namespace, item.Name, item.Value), string.Empty, 0, ref fireAgain);
        }

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

现在,当我运行该程序包时,我在Visual Studio中的输出"选项卡(可以在其中全部选择)+图形结果选项卡将包含所有这些信息消息.运行程序包时,如果我将2005/2008或2012+与程序包部署模型一起使用,则需要确保我具有/rep eiw的参数,以将错误,信息和警告事件捕获到作业日志或控制台或什么(默认情况是仅报告错误).具有项目部署模型的2012+版本将自动将信息捕获到SSISDB.catalog.operation_messages表中.

Now when I run the package, my output tab in Visual Studio (where I can select it all) + the graphical results tab will have all of those information messages. When I run the package, if I'm using 2005/2008 or 2012+ with the package deployment model, I need to ensure I have the argument of /rep eiw to capture Errors, information and Warning events to the job log or console or whatever (the default is to only report Errors). 2012+ with project deployment model will automagically capture Information to the SSISDB.catalog.operation_messages table.

这篇关于MessageBox.Show会在服务器端引起超时问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆