Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I realized simple healthcheck in my site. I need to know, is connection to database ok or not. For this I want to ping it. How to ping database from api controller code?
if your db connection is not correct umbraco will not work, you will get an error trying to access it, so if you are in umbraco then your dbis working.
It's not always true.
When I stop Database and call /umbraco/api/keepalive/ping, it returns
<Message>I'm alive!</Message> <Success>true</Success>
But I have to know the state of the database connection.
Is there some controller that gives information on the state of the database?
a ping will only tell you if the server is up or not, not whether something running on the server is running.
Did you try turning of the db and then trying to load umbraco? it won't load if the database is not active. So not sure what you are trying to achieve with your check and to what purpose?
If your database is not live, you won't be able to load umbraco to check the database
I did this solution
private int GetDataBaseCode()
using (var scope = Current.ScopeProvider.CreateScope(autoComplete: true))
state = scope.Database.Connection.State;
state = ConnectionState.Broken;
return state == ConnectionState.Open ? 200 : 500;
I think the best way to use IUmbracoDatabaseFactory
private readonly IUmbracoDatabaseFactory _umbracoDatabaseFactory;
public YOURController(IUmbracoDatabaseFactory umbracoDatabaseFactory)
_umbracoDatabaseFactory = umbracoDatabaseFactory;
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted