2 // System.Configuration.ConnectionStringSettings.cs
5 // Sureshkumar T <tsureshkumar@novell.com>
6 // Chris Toshok <toshok@ximian.com>
9 // Copyright (C) 2004,2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.ComponentModel;
36 namespace System.Configuration
38 public sealed class ConnectionStringSettings : ConfigurationElement
40 private static ConfigurationPropertyCollection _properties;
42 private static readonly ConfigurationProperty _propConnectionString;
43 private static readonly ConfigurationProperty _propName;
44 private static readonly ConfigurationProperty _propProviderName;
46 static ConnectionStringSettings ()
48 _properties = new ConfigurationPropertyCollection ();
49 _propName = new ConfigurationProperty ("name", typeof(string), null,
50 TypeDescriptor.GetConverter (typeof (string)),
51 new StringValidator (1),
52 ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
54 _propProviderName = new ConfigurationProperty ("providerName", typeof (string), "System.Data.SqlClient",
55 ConfigurationPropertyOptions.None);
57 _propConnectionString = new ConfigurationProperty ("connectionString", typeof (string), "",
58 ConfigurationPropertyOptions.IsRequired);
60 _properties.Add (_propName);
61 _properties.Add (_propProviderName);
62 _properties.Add (_propConnectionString);
65 public ConnectionStringSettings ()
69 public ConnectionStringSettings (string name, string connectionString)
70 : this (name, connectionString, "System.Data.SqlClient")
74 public ConnectionStringSettings (string name, string connectionString, string providerName)
77 ConnectionString = connectionString;
78 ProviderName = providerName;
81 protected internal override ConfigurationPropertyCollection Properties
83 get { return _properties; }
86 [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
89 get { return (string) base [_propName];}
90 set { base [_propName] = value; }
93 [ConfigurationProperty ("providerName", DefaultValue = "System.Data.SqlClient")]
94 public string ProviderName
96 get { return (string) base [_propProviderName]; }
97 set { base [_propProviderName] = value; }
100 [ConfigurationProperty ("connectionString", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired)]
101 public string ConnectionString
103 get { return (string) base [_propConnectionString]; }
104 set { base [_propConnectionString] = value; }
107 public override string ToString ()
109 return ConnectionString;