I am developing a C# desktop application for my client that uses MySQL Server. What my client demands is that the database server should be started at the time of application start and also it should be stopped at the application exit. I know how to start a process in C# using Process.Start() but what I don't know is that how to detect the installation path of the MySQL server and start the server because the condition of my client is that the server installation path may change in future. Also I don't know how to stop a process/service in C#. So please tell me these two things:
- Detect installation path of MySQL and start the server via C#
- Stop the MySQL server on application exit via C#
I tried this but this code needs the path of the MySql installation. I need the path automatic and I am unable to predict any code for that
if (Process.GetProcessesByName("mysqld.exe") == null)
{
Process.Start("C:\Program Files (x86)\MySQL\MySQL Cluster 5.5\bin\mysqld.exe");
}