
This article was written in 2022. Versions, tools and recommendations may have changed since then. Newer posts are collected under .NET.
Sometimes it is quite useful to be able to send a query to the MSSQL server independently of its schema; for example to check if the server is principally reachable and the connection information as well as the credentials are correct.
This is also very useful for the health checks in ASP.NET Core or Azure App Service , to check if the state is healthy while generating the least possible database load.
SELECT 1
So the goal is to send the server a message that it can answer immediately without dependencies. For this you can use a special feature, where all databases have this feature implemented in some way.
In the case of the MSSQL server it is SELECT 1;
SELECT 1So the server is sent a query that has only a SELECT, where the numeric value also corresponds to the answer.
So a SELECT 1 becomes the answer 1.
There must be a database on the server to connect to, but no tables must be deployed.
Entity Framework
In addition to handling with entities, the Entity Framework can also work directly with Raw SQL. For this purpose the method ExecuteSqlRawAsync can be used.
Since we are in principle only interested in the execution (an exception should therefore be thrown if it does not work) but not the result (here 1), the following basic implementation is sufficient.
This method can now be used for pings.
Related articles

- 11 min read
Containerizing .NET in 2026 Without a Dockerfile
Most .NET Dockerfiles repeat the same five steps: restore, publish, select the matching Microsoft runtime image, copy the output and start …

- 12 min read
Problem Details in ASP.NET Core and .NET 11
builder.Services.AddProblemDetails() registers infrastructure. It does not create an error contract. An ASP.NET Core request can fail during …

- 11 min read
Resilience in .NET with Microsoft.Extensions.Resilience
Retries are the most visible resilience strategy and the easiest one to misuse. Repeating a failing call can recover from a short network …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.
