从 Windows 服务运行 SSIS 包时出现问题

发布于 2024-11-15 14:18:23 字数 2660 浏览 2 评论 0原文

我创建了一个每五分钟执行一次 SSIS 包的 Windows 服务。它工作得很好,但有些东西让它出错了。

每周服务器都会重新启动,重新启动后,服务将停止工作。 SSIS 包开始/结束执行的事件仍然出现在事件查看器中,但该包无法正常工作。当我手动启动/停止服务时,一切又恢复正常。

我是否遗漏了一些我应该用 Pacakge 做的事情?

我使用 Web 服务来获取 SSIS 包的位置。我从下面的代码中删除了大部分内容,但留下了足够的内容以维持我的服务结构。

这是我的代码的要点:

namespace MyService
{
    partial class MyService : ServiceBase
    {
        private Timer timer;
        private Package pkg;
        bool executing;

        public MyService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            executing = false;
            TimerCallback callback = new TimerCallback(Init);
            int period = 1000 * 60; //attempt to initialize every minute.
            timer = new Timer(callback, null, 0, period);
        }


        private void Init(object state)
        {
            try
            {
                //Get `timeIntervalMinutes` from Parameters table
                string mySQLStatement = "...";
                DataSet ds = mySQLQuery(...);
                int timeIntervalMinutes = Convert.ToInt32(ds.Tables["timeIntervalMinutes"].Rows[0]["Value"]);

                //Get `path` from Parameters table
                string mySQLStatement = "...";
                DataSet ds = mySQLQuery(...);
                string path = Convert.ToString(ds.Tables["path"].Rows[0]["Value"]);

                //Get `path` from Parameters table
                string mySQLStatement = "...";
                DataSet ds = mySQLQuery(...);
                string server = Convert.ToString(ds.Tables["server"].Rows[0]["Value"]);

                //Load the SSIS Package
                Application app = new Application();
                pkg = app.LoadFromDtsServer(path, server, null);

                //If this line is reached, a connection to MyWS has been made, so switch the timer to run the SSIS package
                timer.Dispose();
                TimerCallback callback = new TimerCallback(OnTimedEvent);
                int period = 1000 * 60 * timeIntervalMinutes;
                timer = new Timer(callback, null, 0, period);
            }
            catch (Exception e)
            {
                return;
            }
        }


        private void OnTimedEvent(object state)
        {
            if (!executing)
            {
                executing = true;
                DTSExecResult pkgResults = pkg.Execute();
                executing = false;
            }
        }

        protected override void OnStop()
        {

        }

        //<MyWS is here>

    }
}

感谢您的帮助!

I created a Windows Service that executes a SSIS Package every five minutes. It works pretty well, but something is tripping it up.

Every week the server restarts, and after the restart, the Service stops working. Events for the SSIS Package beginning/ending executions still appear in the event viewer, but the package doesn't work as it should. When I manually start/stop the service, all works as normal again.

Am I missing something that I should be doing with the Pacakge?

I use a web service to get the location of the SSIS Package. I stripped most of that out of the code below, but left enough of it that the structure of my service is maintained.

Here is the jist of my code:

namespace MyService
{
    partial class MyService : ServiceBase
    {
        private Timer timer;
        private Package pkg;
        bool executing;

        public MyService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            executing = false;
            TimerCallback callback = new TimerCallback(Init);
            int period = 1000 * 60; //attempt to initialize every minute.
            timer = new Timer(callback, null, 0, period);
        }


        private void Init(object state)
        {
            try
            {
                //Get `timeIntervalMinutes` from Parameters table
                string mySQLStatement = "...";
                DataSet ds = mySQLQuery(...);
                int timeIntervalMinutes = Convert.ToInt32(ds.Tables["timeIntervalMinutes"].Rows[0]["Value"]);

                //Get `path` from Parameters table
                string mySQLStatement = "...";
                DataSet ds = mySQLQuery(...);
                string path = Convert.ToString(ds.Tables["path"].Rows[0]["Value"]);

                //Get `path` from Parameters table
                string mySQLStatement = "...";
                DataSet ds = mySQLQuery(...);
                string server = Convert.ToString(ds.Tables["server"].Rows[0]["Value"]);

                //Load the SSIS Package
                Application app = new Application();
                pkg = app.LoadFromDtsServer(path, server, null);

                //If this line is reached, a connection to MyWS has been made, so switch the timer to run the SSIS package
                timer.Dispose();
                TimerCallback callback = new TimerCallback(OnTimedEvent);
                int period = 1000 * 60 * timeIntervalMinutes;
                timer = new Timer(callback, null, 0, period);
            }
            catch (Exception e)
            {
                return;
            }
        }


        private void OnTimedEvent(object state)
        {
            if (!executing)
            {
                executing = true;
                DTSExecResult pkgResults = pkg.Execute();
                executing = false;
            }
        }

        protected override void OnStop()
        {

        }

        //<MyWS is here>

    }
}

Thanks for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与清晨阳光 2024-11-22 14:18:23

您的服务或流程可能依赖于其他服务 - 例如 MSDTC。如果该服务在启动后没有准备好,您可能会得到不可预测的结果。延迟服务的启动或找出依赖项并在服务属性中进行设置

Your service or process maybe dependent on another service - say MSDTC. IF this service is not ready as quickly after startup you could get unpredictable results. Either delay the startup of your service or figure out the dependency and set is in the service properties

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文