0

Im working in windows service syncmysqldb.exe i need the service to run a process ie syncing of two mysql databases in n intervals of time given in setting.xml file

When i install this service service manager i see the service not in started state and when i try to run in manually by right clicking it gives following error

When i install service it gives following error The description for Event ID ( 11001 ) in Source ( MsiInstaller ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Product: SetupSynMysqldb -- Error 1001. Error 1001. An exception occurred during the Commit phase of the installation. This exception will be ignored and installation will continue. However, the application might not function correctly after installation is complete. --> The savedState dictionary contains inconsistent data and might have been corrupted., (NULL), (NULL), (NULL), (NULL), , .

When i run service in service manager it gives following error The SyncMysqlDb service failed to start due to the following error: The system cannot find the file specified.

C# code

 protected override void OnStart(string[] args)
            {
                try
                {
                    //add this line to text file during start of service

                    EventLog.WriteEntry("SyncMysqlDb in OnStart. at " + DateTime.Now);
                    //handle Elapsed event
                    tmrSync.Elapsed += new ElapsedEventHandler(OnElapsedTime);



                    tmrSync.Interval = GetIntervals();

                    //enabling the timer
                    tmrSync.Enabled = true;
                    //TraceService(" tmrSync.Interval =" + tmrSync.Interval + " at " + DateTime.Now);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ServiceWorkerThread));
                }
                catch (Exception ex)
                {

                    EventLog.WriteEntry("Service failed to start.", EventLogEntryType.Error, (int)Service1EventIds.Start_InitializationFailure, ex);
                }
            }
private void ServiceWorkerThread(object state)
        {
            // Periodically check if the service is stopping.
            while (!this.stopping)
            {
                // Perform main service function here...

                Thread.Sleep(2000);  // Simulate some lengthy operations.
            }

            // Signal the stopped event.
            this.stoppedEvent.Set();
        }
        protected override void OnStop()
        {
            tmrSync.Enabled = false;
            //TraceService("stopping service" + DateTime.Now);
            EventLog.WriteEntry("SyncMysqlDb in OnStop. at " + DateTime.Now);
            this.stopping = true;
            this.stoppedEvent.WaitOne();
        }
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {

            try
            {
                EventLog.WriteEntry(@"Executing C:\SyncMysqlDbRepository\task.bat at " + DateTime.Now);
                Process.Start(@"C:\SyncMysqlDbRepository\task.bat");
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("Service failed to start.at " + DateTime.Now, EventLogEntryType.Error, (int)Service1EventIds.Start_InitializationFailure, ex);

            }
           // TraceService("syncing db at " + DateTime.Now);
        }
        protected int GetIntervals()
        {
            var dt = new DataTable();
            try
            {

                dt.ReadXmlSchema(@"C:\SyncMysqlDbRepository\SettingsDs.xml");
                dt.ReadXml(@"C:\SyncMysqlDbRepository\Settings.xml");

            }
            catch (Exception ex)
            {

                 EventLog.WriteEntry("GetIntervals  failed at " + DateTime.Now, EventLogEntryType.Error, (int)Service1EventIds.Start_InitializationFailure, ex);
                return 0;
            }
            return Convert.ToInt16(dt.Rows[0].ItemArray[2]); //Intervals from settings.xml
        }
4

0 回答 0