How to inizialize connection string
In my inizialisation class I have to variants of how to inizialize connection string. But in fact I want to have one common case.

here is the first one that is used when inizialization is making by the connection string dirrectly in the code:

    public static SqlConnection GetConnection()
            {
                if (string.IsNullOrEmpty(_connectionString))
                    throw new ApplicationException(string.Format("Connection string is not specified."));
    
                return new SqlConnection(_connectionString);
            }

the second variant is used when I need to take my connection string from app.config:

  

 

    public static SqlConnection GetConnection()
        {
    
            string connectionString = ConfigurationManager.ConnectionStrings[_connectionString].ConnectionString;
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ApplicationException(string.Format("Connection string {0} is not found", _connectionString));
            }
            return new SqlConnection(connectionString);
        }

Can you help me to make one common vqriant for both ways of inizialization?

How to inizialize connection string
===

In my inizialisation class I have to variants of how to inizialize connection string. But in fact I want to have one common case.

here is the first one that is used when inizialization is making by the connection string dirrectly in the code:

    public static SqlConnection GetConnection()
            {
                if (string.IsNullOrEmpty(_connectionString))
                    throw new ApplicationException(string.Format("Connection string is not specified."));
    
                return new SqlConnection(_connectionString);
            }

the second variant is used when I need to take my connection string from app.config:

  

 

    public static SqlConnection GetConnection()
        {
    
            string connectionString = ConfigurationManager.ConnectionStrings[_connectionString].ConnectionString;
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ApplicationException(string.Format("Connection string {0} is not found", _connectionString));
            }
            return new SqlConnection(connectionString);
        }

Can you help me to make one common vqriant for both ways of inizialization?
