Answers for "check connection sql server c#"

SQL
1

how to check connection with sql server in c#

/// <summary>
/// Test that the server is connected
/// </summary>
/// <param name="connectionString">The connection string</param>
/// <returns>true if the connection is opened</returns>
private static bool IsServerConnected(string connectionString)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        try
        {
            connection.Open();
            return true;
        }
        catch (SqlException)
        {
            return false;
        }
    }
}
Posted by: Guest on September-21-2021

Code answers related to "check connection sql server c#"

Code answers related to "SQL"

Browse Popular Code Answers by Language