SQL Server Test connection to UiPath with CODE

Hi everyone,

I remember in C# that before sending any command to perform a CRUD we used to ‘Test’ the connection to the DB first using a small Script/code. There is a activity who does that of course but I was wondering:

•Has anyone tried to ‘Test the connection’ to a Database with a Script/Code?

It would be good to get a boolean result, any 0, 1, true or false in order to use an ‘If’ afterward.

Thanks for any suggestions in advance!

Be Safe!

What would be the database server you want this for? If Sql Server you could do something simple like this:

public bool IsServerConnected()
    {
        using (var l_oConnection = new SqlConnection(DBConnection.ConnectionString))
        {
            try
            {
                l_oConnection.Open();
                return true;
            }
            catch (SqlException)
            {
                return false;
            }
        }
    }