Загрузка данных


using ConsoleApp3009;
using Microsoft.Data.SqlClient;
using System.Data.SqlTypes;
using System.Drawing;
internal class Program
{
    private static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");

        SqlConnection? connection = null;
        SqlConnection? command = null;
        SqlDataReader? reader = null;


        try
        {
            string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=GossenPR1;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False";

            connection = new SqlConnection(connectionString);
            connection.Open();

            if (connection.State == System.Data.ConnectionState.Open)
            {
                ColorConsole.WriteLine(ConsoleColor.Green,
                    $"Подключение установленно\n");
            }
            else
            {
                ColorConsole.WriteLine(ConsoleColor.Red,
                    $"Подключение прервано\n");

            }


        }
        catch (Exception ex)
        {
            ColorConsole.WriteLine(ConsoleColor.Red, $"Внимание! Ошибка! \n[ex.ToString()]\n\n");
        }
        finally
        {
            if (connection != null)
            {
                connection.Close();
            }
        }


    }
}

__________________________________________________________________________ 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3009
{
    public static class ColorConsole
    {
        public static void Write(ConsoleColor color, string str)
        {
                Console.ForegroundColor = color;
                Console.Write(str);
                Console.ForegroundColor = ConsoleColor.Gray;
        }
        public static void WriteLine(ConsoleColor color, string str)
        {
            Write(color, str);
            Console.WriteLine();
        }
    }
}