开发者

Problem Running SSIS Package from Windows Service

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开发者_如何学Python 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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜