using System;
using System.Data;
using System.Data.SqlClient;

namespace DBCONNECTION
{
    class DbClass
    {
        public SqlConnection DbConnection(string str)
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = str;
            connection.Open();
            return connection;
        }
    }

    class MainClass
    {
        public static void Main()
        {
            DbClass dc = new DbClass();
            SqlConnection con1 = dc.DbConnection("server=localhost;database=pubs;uid=sa;pwd=#tlqkfdk");
            SqlConnection con2 = dc.DbConnection("server=localhost;database=northwind;uid=sa;pwd=#tlqkfdk");
            
            try
            {
                //con1.Open();
                //con2.Open();

                if(con1.State == ConnectionState.Open)
                {
                    Console.WriteLine("첫번째 연결이 성공되었습니다.");
                    ViewDbState(con1);
                }

                if(con2.State == ConnectionState.Open)
                {
                    Console.WriteLine("두번째 연결이 성공되었습니다.");
                    ViewDbState(con2);
                }
            }
            catch(Exception E)
            {
                Console.WriteLine(E.Message);
            }
            finally
            {
                con1.Close();
                con2.Close();
            }

        }

        public static void ViewDbState(SqlConnection connection)
        {
            Console.WriteLine(connection.ServerVersion);
            Console.WriteLine(connection.Database);
            Console.WriteLine(connection.State.ToString());
        }
    }
}