BuildConnectionString solution : SqlConnectionStringBuilder « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data.SqlClient;

    class Program
    {
        static void Main(string[] args)
        {
            SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder(  );

            csb.DataSource = "(local)";
            csb.Add("Initial Catalog", "AdventureWorks");
            csb["Integrated Security"] = true;

            Console.WriteLine("Connection string:\n{0}", csb.ConnectionString);

            SqlConnection connection = new SqlConnection(csb.ConnectionString);
            connection.Open(  );
            Console.WriteLine("\nConnectionState = {0}", connection.State);
            connection.Close(  );
            Console.WriteLine("ConnectionState = {0}", connection.State);


        }
    }








32.16.SqlConnectionStringBuilder
32.16.1.Build SqlConnectionStringBuilder from connection string
32.16.2.Build a connection string from component parameters and display it
32.16.3.BuildConnectionString solution