1.NuGet 에서 System.Configuration.ConfigurationManager 설치
2.App.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> </startup> <connectionStrings> <add name="REG" connectionString="Server=SQLOLEDB.1;Password=password01;Persist Security Info=True;User ID=REG001;Initial Catalog=REG;Data Source=MYPC"/--> <add name="REG_Entities" connectionString="metadata=res://*/RuleVariable.csdl|res://*/RuleVariable.ssdl|res://*/RuleVariable.msl;provider=System.Data.SqlClient;provider connection string="data source=MYPC;initial catalog=REG;user id=REG;password=password01;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> <!--AppSettings> <add key="CacheTime" value="60"/> </AppSettings--> <appSettings> <add key="CacheTime" value="60"/> </appSettings> </configuration> |
3.소스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
using System; using System.Data; using System.Runtime.Caching; using System.Data.SqlClient; using System.Configuration; ::::::: 중략 :::::: public DataSet FilterData(ArsonFilterModel filterData) { var connectionString = ConfigurationManager.ConnectionStrings["UCR_DataEntities"]; DataSet dsResult = new DataSet(); using (SqlConnection conn = new SqlConnection(connectionString.ConnectionString)) { try { SqlCommand command = new SqlCommand(); command.Connection = conn; command.CommandText = GenerateArsonORQuery(filterData); command.CommandType = System.Data.CommandType.Text; SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = command; conn.Open(); adapter.Fill(dsResult); conn.Close(); adapter.Dispose(); command.Dispose(); } catch (Exception ex) { StorageClient.LogError(ex); } } return dsResult; } |