Answered by:
Start mysql server from asp.net core web application.

Question
-
User-1204637165 posted
Dear All,
I have a web application running on a local area network that I built with asp.net core and mysql db.
I want to konw if it is possible for my web application to kick start mysql server anytime the application is visited.
The web applicaiton should also be able to check if the web server is turned off.
So incase the mysql server is off the web application can call a bat command to restart it.
Thursday, July 18, 2019 6:35 PM
Answers
-
User-474980206 posted
you will need to detect you are currently starting the mysql app, so you don't try to start more than 1 at a time. you will also want to decide if the idle exit of the core app, should kill the mysql process. normally you would have a handle to it, that you should close on exit.
note: normally you'd run mysql as service, not a child process of the web server
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 19, 2019 1:23 AM -
User-854763662 posted
>>so when I boot the system mysql comes on immediately. Please is that sufficient ??????. if it is then maybe I should not bother running or starting from asp.net core.
Have you already achieved start mysql from .net core application?
In my option, we should avoid starting and stopping service from .net core application which is not reasonable. The mysql application is independent, and we should control the service lifecycle by ourself.
.Net Core application should only connect and operate the database when mysql is available.
Best Regards,
Sherry
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 19, 2019 10:11 AM -
User753101303 posted
Hi,
Usually when you have a server whatever you need to be up and running is just launched at startup.
For Windows it seems they recommend installing MySQL as a service: https://dev.mysql.com/doc/refman/8.0/en/windows-start-service.html
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 19, 2019 10:21 AM
All replies
-
User475983607 posted
I want to konw if it is possible for my web application to kick start mysql server anytime the application is visited.Try to open a connection. You'll get a connection exception if the service is not running.
The web applicaiton should also be able to check if the web server is turned off.You want the web server to check if MySql is installed but the service is not started? I think you need MySQL support for this type of requirement.
https://dev.mysql.com/doc/refman/8.0/en/windows-start-command-line.html
Thursday, July 18, 2019 7:11 PM -
User-1204637165 posted
Thanks so is it possible to trigger the command to start the ssql server if it is off or trigger a bat file that would start that command.
Thursday, July 18, 2019 7:49 PM -
User-474980206 posted
you will need to detect you are currently starting the mysql app, so you don't try to start more than 1 at a time. you will also want to decide if the idle exit of the core app, should kill the mysql process. normally you would have a handle to it, that you should close on exit.
note: normally you'd run mysql as service, not a child process of the web server
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 19, 2019 1:23 AM -
User-1204637165 posted
Tank u bruce,
Normally when I want to start mysql I just put that command in the shell:startup folder of windows. So I create a run.bat file referencing the path to were mysqld.exe is located.
I kept my run.bat file in my startup folder of windows OS.
so when I boot the system mysql comes on immediately. Please is that sufficient ??????. if it is then maybe I should not bother running or starting from asp.net core.
Thanks alot.
Friday, July 19, 2019 4:18 AM -
User1120430333 posted
IMHO, what you are talking about is a little far fetched and probably not viable.
Friday, July 19, 2019 7:36 AM -
User-854763662 posted
>>so when I boot the system mysql comes on immediately. Please is that sufficient ??????. if it is then maybe I should not bother running or starting from asp.net core.
Have you already achieved start mysql from .net core application?
In my option, we should avoid starting and stopping service from .net core application which is not reasonable. The mysql application is independent, and we should control the service lifecycle by ourself.
.Net Core application should only connect and operate the database when mysql is available.
Best Regards,
Sherry
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 19, 2019 10:11 AM -
User753101303 posted
Hi,
Usually when you have a server whatever you need to be up and running is just launched at startup.
For Windows it seems they recommend installing MySQL as a service: https://dev.mysql.com/doc/refman/8.0/en/windows-start-service.html
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 19, 2019 10:21 AM