how to check connection with sql server in c 23

Solutions on MaxInterview for how to check connection with sql server in c 23 by the best coders in the world

showing results for - "how to check connection with sql server in c 23"
Clara
15 Nov 2016
1/// <summary>
2/// Test that the server is connected
3/// </summary>
4/// <param name="connectionString">The connection string</param>
5/// <returns>true if the connection is opened</returns>
6private static bool IsServerConnected(string connectionString)
7{
8    using (SqlConnection connection = new SqlConnection(connectionString))
9    {
10        try
11        {
12            connection.Open();
13            return true;
14        }
15        catch (SqlException)
16        {
17            return false;
18        }
19    }
20}