public static void Test_Config_File() { // use the demo to use App.config file to get connstr and customized variable value string connectionString = ConfigurationManager.ConnectionStrings["SQL_Connection"].ConnectionString; Console.WriteLine("C4_Listing29_30, ConnStr is:{0}", connectionString); string Setting_Value = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["Setting1"].Value.ToString(); Console.WriteLine("C4_Listing29_30, Setting1 is:{0}", Setting_Value); C4_Listing27.Test_SqlConnection(connectionString); }
public static void Test_SqlConnStrBuilder() { var sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.DataSource = @"HUICHEN"; sqlConnectionStringBuilder.InitialCatalog = "Hui"; sqlConnectionStringBuilder.IntegratedSecurity = true; string connectionString = sqlConnectionStringBuilder.ToString(); Console.WriteLine("C4_Listing28, ConnStr is:{0}", connectionString); C4_Listing27.Test_SqlConnection(connectionString); }