markus / MarkusLogview / MarkusDataModel / Common / ConnectStringBuilder.cs @ ddc223b4
이력 | 보기 | 이력해설 | 다운로드 (5.19 KB)
1 | 84578b97 | djkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Data.EntityClient; |
||
4 | using System.Data.SqlClient; |
||
5 | using System.Linq; |
||
6 | using System.Text; |
||
7 | |||
8 | namespace MarkusDataModel.Common |
||
9 | { |
||
10 | public class ConnectStringBuilder |
||
11 | { |
||
12 | |||
13 | |||
14 | private const string InitialCatalogString = "InitialCatalog"; |
||
15 | private const string providerName = "System.Data.SqlClient"; |
||
16 | |||
17 | //private const string providerName = "MS.Data.MySqlClient"; //MYSQL 일때 사용 |
||
18 | //private const string MEMBERMeta = @"res://*/DataModel.MEMBERModel.csdl|res://*/DataModel.MEMBERModel.ssdl|res://*/DataModel.MEMBERModel.msl;"; |
||
19 | |||
20 | // 개발용 테스트 ( DevMarkusModel ) |
||
21 | private const string MarkusMeta = @"res://*/DataModel.CloudMarkusModel.csdl|res://*/DataModel.CloudMarkusModel.ssdl|res://*/DataModel.CloudMarkusModel.msl"; |
||
22 | private const string MarkusCIMeta = @"res://*/DataModel.CloudMarkusCIModel.csdl|res://*/DataModel.CloudMarkusCIModel.ssdl|res://*/DataModel.CloudMarkusCIModel.msl"; |
||
23 | private const string MarkusEntitiesMeta = @"res://*/DataModel.markusEntities.csdl|res://*/DataModel.markusEntities.ssdl|res://*/DataModel.markusEntities.msl"; |
||
24 | //private const string MarkusEntitiesMeta = @"res://*/DataModel.HyosungMarkusEntities.csdl|res://*/DataModel.HyosungMarkusEntities.ssdl|res://*/DataModel.HyosungMarkusEntities.msl"; |
||
25 | |||
26 | |||
27 | // 클라우드 ( MarkusModel ) |
||
28 | //private const string MarkusMeta = @"res://*/DataModel.MarkusModel.csdl|res://*/DataModel.DevMarkusModel.ssdl|res://*/DataModel.DevMarkusModel.msl;"; |
||
29 | //private const string MarkusCIMeta = @"res://*/DataModel.MarkusCIModel.csdl|res://*/DataModel.DevMarkusCIModel.ssdl|res://*/DataModel.DevMarkusCIModel.msl;"; |
||
30 | public static EntityConnectionStringBuilder MarkusConnectionString() |
||
31 | { |
||
32 | SqlConnectionStringBuilder _bl = new SqlConnectionStringBuilder(string.Format(Properties.Settings.Default.ProjectConnectionString, "markus")); |
||
33 | return EntityConnectionStringBuilder(_bl, MarkusMeta); |
||
34 | } |
||
35 | //public static EntityConnectionStringBuilder ProjectCIConnectString(string ProjectNo) |
||
36 | //{ |
||
37 | // return CIConnectionStringBuilder(Properties.Settings.Default.ProjectConnectionString, ProjectNo, MarkusCIMeta); |
||
38 | //} |
||
39 | public static EntityConnectionStringBuilder MarkusEntitiesConnectionString() |
||
40 | { |
||
41 | SqlConnectionStringBuilder _bl = new SqlConnectionStringBuilder(string.Format(Properties.Settings.Default.ProjectConnectionString, "markus")); |
||
42 | return EntityConnectionStringBuilder(_bl, MarkusEntitiesMeta); |
||
43 | } |
||
44 | |||
45 | |||
46 | // 현재는 안쓰임 |
||
47 | //public static EntityConnectionStringBuilder MEMBERConnectString() |
||
48 | //{ |
||
49 | // SqlConnectionStringBuilder _bl = new SqlConnectionStringBuilder(string.Format(Properties.Settings.Default.ProjectConnectionString, "markus")); |
||
50 | // return EntityConnectionStringBuilder(_bl, MEMBERMeta); |
||
51 | //} |
||
52 | |||
53 | //private static EntityConnectionStringBuilder CIConnectionStringBuilder(string adoConnectionString, string ProjectNo, string Metadata) |
||
54 | //{ |
||
55 | // try |
||
56 | // { |
||
57 | // SqlConnectionStringBuilder bl = new SqlConnectionStringBuilder(string.Format(Properties.Settings.Default.ProjectConnectionString, "markus")); |
||
58 | |||
59 | // using (DataModel.CloudMarkusEntities entity |
||
60 | // = new DataModel.CloudMarkusEntities(EntityConnectionStringBuilder(bl, MarkusMeta).ToString())) |
||
61 | // { |
||
62 | // var _catalog = entity.PROPERTIES.Where(property => property.TYPE == InitialCatalogString && property.PROPERTY == ProjectNo); |
||
63 | // EntityConnectionStringBuilder builder = null; |
||
64 | // if (_catalog.Count() > 0) |
||
65 | // { |
||
66 | // string _ConnectionString = string.Format(adoConnectionString, _catalog.First().VALUE); |
||
67 | // SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(_ConnectionString); |
||
68 | |||
69 | // builder = ConnectStringBuilder.EntityConnectionStringBuilder(sqlBuilder, Metadata); |
||
70 | // } |
||
71 | |||
72 | // return builder; |
||
73 | // } |
||
74 | // } |
||
75 | // catch (Exception ex) |
||
76 | // { |
||
77 | // System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
78 | // } |
||
79 | |||
80 | // return null; |
||
81 | //} |
||
82 | |||
83 | private static EntityConnectionStringBuilder EntityConnectionStringBuilder(SqlConnectionStringBuilder SqlStringBuilder, string EntityMetaData) |
||
84 | { |
||
85 | string providerString = SqlStringBuilder.ToString(); |
||
86 | |||
87 | EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(); |
||
88 | |||
89 | entityBuilder.Provider = providerName; |
||
90 | entityBuilder.ProviderConnectionString = providerString; |
||
91 | entityBuilder.Metadata = EntityMetaData; |
||
92 | Console.WriteLine(entityBuilder.ToString()); |
||
93 | |||
94 | using (EntityConnection conn = |
||
95 | new EntityConnection(entityBuilder.ToString())) |
||
96 | { |
||
97 | conn.Open(); |
||
98 | Console.WriteLine("Just testing the connection."); |
||
99 | conn.Close(); |
||
100 | } |
||
101 | |||
102 | return entityBuilder; |
||
103 | } |
||
104 | |||
105 | } |
||
106 | } |