How to start MYSQL service in front of my windows service

I have a windows utility that starts and sometime throws an exception regarding a null reference to a system. After my investigation, this is due to the fact that the MySQL connection cannot be established due to the fact that the MySql instance is not already running when the computer starts. How to solve these problems?

early

+1
source share
3 answers

You can install the dependencies of each service on Windows.

You can enter the control panel → "Administration" → "Services" (or run "services.msc" from the command line). By double-clicking on any of the services and going to the Dependencies tab, you can see what each service relies on.

Your service depends on the MySql service, so MySql should be in the list of dependencies for it.

You can add items depending, here is a description of how to do this:

https://serverfault.com/questions/24821/how-to-add-dependency-on-a-windows-service-after-the-service-is-installed

+2
source

In this article, you can make it clear how dependent on the code service is:

http://bloggingabout.net/blogs/jschreuder/archive/2006/12/07/How-to_3A00_-Code-Service-Dependencies.aspx

+1
source

Try using the following code if you want to do it yourself without dependencies

//Check if service is running ServiceController mysqlServiceController = new ServiceController(); mysqlServiceController.ServiceName = "MySql"; var timeout = 3000; //Check if the service is started if (mysqlServiceController.Status == System.ServiceProcess.ServiceControllerStatus.Stopped || mysqlServiceController.Status == System.ServiceProcess.ServiceControllerStatus.Paused) { mysqlServiceController.Start(); try { //Wait till the service runs mysql ServiceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, new TimeSpan(0, timeout, 0)); } catch (System.ServiceProcess.TimeoutException) { //MessageBox.Show(string.Format("Starting the service \"{0}\" has reached to a timeout of ({1}) minutes, please check the service.", mysqlServiceController.ServiceName, timeout)); } } 
+1
source

All Articles