Store ConnectionStringConfig solution : AppSettingsReader « Development « C# / CSharp Tutorial






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

    class Program
    {
        static void Main(string[] args)
        {
            foreach (ConnectionStringSettings css in ConfigurationManager.ConnectionStrings)
            {
                Console.WriteLine(css.Name);
                Console.WriteLine(css.ProviderName);
                Console.WriteLine(css.ConnectionString);
            }

            string sqlConnectString =ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
            SqlConnection connection = new SqlConnection(sqlConnectString);
            connection.Open(  );
            Console.WriteLine("Connection string state = {0}", connection.State);
            connection.Close(  );
            Console.WriteLine("Connection string state = {0}", connection.State);
        }
    }








14.12.AppSettingsReader
14.12.1.Use AppSettingsReader to load settings from app.config
14.12.2.For programmatic access to .NET *.config files
14.12.3.Store ConnectionStringConfig solution