private static async tryConnection()

in src/SqlUtils.ts [54:86]


    private static async tryConnection(config: SqlConnectionConfig, useMaster?: boolean): Promise<ConnectionResult> {
        const database = useMaster ? "master" : config.Database;
        
        let sqlCmdError = '';
        try {
            core.debug(`Validating if client has access to '${database}' on '${config.Server}'.`);
            let sqlCmdCall = this.buildSqlCmdCallWithConnectionInfo(config, database);
            sqlCmdCall += ` -Q "SELECT 'Validating connection from GitHub SQL Action'"`;
            await exec.exec(sqlCmdCall, [], {
                silent: true,
                listeners: {
                    stderr: (data: Buffer) => sqlCmdError += data.toString(),
                    // Some AAD errors come through as regular stdout. For this scenario, we will just append any stdout 
                    // to the error string since it will only be surfaced if sqlcmd actually fails.
                    stdout: (data: Buffer) => sqlCmdError += data.toString()
                }
            });

            // If we reached here it means connection succeeded
            return {
                success: true
            };
        }
        catch (error) {
            core.debug(`${error.message}`);
            core.debug(`SqlCmd stderr: ${sqlCmdError}`);
            return {
                success: false,
                errorMessage: sqlCmdError,
                ipAddress: this.parseErrorForIpAddress(sqlCmdError)
            };
        }
    }