ConnectionStringSettingsCollection.Clear 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从集合中移除所有 ConnectionStringSettings 对象。
public:
void Clear();
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()
示例
以下示例演示如何从ConnectionStringSettingsCollection集合中删除所有 ConnectionStringSettings 对象。
// Clear connection strings collection.
static void ClearConnectionStrings()
{
// Get the configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Clear the connection strings collection.
ConnectionStringsSection csSection =
config.ConnectionStrings;
csSection.ConnectionStrings.Clear();
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
Console.WriteLine("Connection strings cleared.");
}
' Clear connection strings collection.
Shared Sub ClearConnectionStrings()
' Get the application configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
' Clear the connection strings collection.
Dim csSection _
As ConnectionStringsSection = _
config.ConnectionStrings
csSection.ConnectionStrings.Clear()
' Save the configuration file.
config.Save(ConfigurationSaveMode.Modified)
Console.WriteLine("Connection strings cleared.")
End Sub
注解
方法 Clear 从当前配置层次结构级别的配置文件中删除所有连接字符串,并在文件中写入标记 <clear>
。 标记 <clear>
表示系统忽略父配置文件中定义的所有连接字符串。