Udostępnij za pośrednictwem


ConnectionStringsSection Klasa

Definicja

Zapewnia programowy dostęp do sekcji configuration-file parametrów połączenia.

public ref class ConnectionStringsSection sealed : System::Configuration::ConfigurationSection
public sealed class ConnectionStringsSection : System.Configuration.ConfigurationSection
type ConnectionStringsSection = class
    inherit ConfigurationSection
Public NotInheritable Class ConnectionStringsSection
Inherits ConfigurationSection
Dziedziczenie

Przykłady

W poniższym przykładzie pokazano, jak używać ConnectionStringsSection.

       // Create a connectionn string element and add it to
       // the connection strings section.
       static ConnectionStrings()
       {
           // Get the application configuration file.
           System.Configuration.Configuration config =
                   ConfigurationManager.OpenExeConfiguration(
                   ConfigurationUserLevel.None);

           // Get the current connection strings count.
           int connStrCnt = 
               ConfigurationManager.ConnectionStrings.Count;

           // Create the connection string name. 
           string csName = 
               "ConnStr" + connStrCnt.ToString();

           // Create a connection string element and
           // save it to the configuration file.
          
           // Create a connection string element.
           ConnectionStringSettings csSettings =
                   new ConnectionStringSettings(csName,
                   "LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;" +
                   "Initial Catalog=aspnetdb", "System.Data.SqlClient");

           // Get the connection strings section.
           ConnectionStringsSection csSection =
               config.ConnectionStrings;

           // Add the new element.
           csSection.ConnectionStrings.Add(csSettings);
               
           // Save the configuration file.
           config.Save(ConfigurationSaveMode.Modified);
       }
' Create a connectionn string element and add it to
' the connection strings section.
Shared Sub New() 

    ' Get the application configuration file.
    Dim config _
    As System.Configuration.Configuration = _
    ConfigurationManager.OpenExeConfiguration( _
    ConfigurationUserLevel.None)
    
    ' Get the current connection strings count.
    Dim connStrCnt As Integer = _
    ConfigurationManager.ConnectionStrings.Count
    
    ' Create the connection string name. 
    Dim csName As String = "ConnStr" + connStrCnt.ToString()
    
    ' Create a connection string element and
    ' save it to the configuration file.
    ' Create a connection string element.
    Dim csSettings _
    As New ConnectionStringSettings( _
    csName, _
    "LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;" + _
    "Initial Catalog=aspnetdb", "System.Data.SqlClient")
    
    ' Get the connection strings section.
    Dim csSection _
    As ConnectionStringsSection = _
    config.ConnectionStrings
    
    ' Add the new element.
    csSection.ConnectionStrings.Add(csSettings)
    
    ' Save the configuration file.
    config.Save(ConfigurationSaveMode.Modified)

End Sub

Poniższy fragment przedstawia konfigurację używaną przez poprzedni przykład.

<?xml version="1.0" encoding="utf-8"?>  
<configuration>  
  <connectionStrings>  
    <add name="ConnStr1" connectionString="LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;Initial Catalog=aspnetdb"  
      providerName="System.Data.SqlClient" />  
  </connectionStrings>  
</configuration>  

Uwagi

Klasa ConnectionStringsSection umożliwia programowe modyfikowanie sekcji connectionStrings pliku konfiguracji. Parametry połączenia są udostępniane jako ConnectionStringSettingsCollection elementów konfiguracji ConnectionStringSettingsadd.

Konstruktory

ConnectionStringsSection()

Inicjuje nowe wystąpienie klasy ConnectionStringsSection.

Właściwości

ConnectionStrings

Pobiera kolekcję ConnectionStringSettingsCollection obiektów ConnectionStringSettings.

CurrentConfiguration

Pobiera odwołanie do wystąpienia najwyższego poziomu Configuration, które reprezentuje hierarchię konfiguracji, do którego należy bieżące wystąpienie ConfigurationElement.

(Odziedziczone po ConfigurationElement)
ElementInformation

Pobiera obiekt ElementInformation zawierający informacje i funkcje obiektu ConfigurationElement, które nie można dostosowywać.

(Odziedziczone po ConfigurationElement)
ElementProperty

Pobiera obiekt ConfigurationElementProperty reprezentujący sam obiekt ConfigurationElement.

(Odziedziczone po ConfigurationElement)
EvaluationContext

Pobiera obiekt ContextInformation dla obiektu ConfigurationElement.

(Odziedziczone po ConfigurationElement)
HasContext

Pobiera wartość wskazującą, czy właściwość CurrentConfiguration jest null.

(Odziedziczone po ConfigurationElement)
Item[ConfigurationProperty]

Pobiera lub ustawia właściwość lub atrybut tego elementu konfiguracji.

(Odziedziczone po ConfigurationElement)
Item[String]

Pobiera lub ustawia właściwość, atrybut lub element podrzędny tego elementu konfiguracji.

(Odziedziczone po ConfigurationElement)
LockAllAttributesExcept

Pobiera kolekcję zablokowanych atrybutów.

(Odziedziczone po ConfigurationElement)
LockAllElementsExcept

Pobiera kolekcję zablokowanych elementów.

(Odziedziczone po ConfigurationElement)
LockAttributes

Pobiera kolekcję zablokowanych atrybutów.

(Odziedziczone po ConfigurationElement)
LockElements

Pobiera kolekcję zablokowanych elementów.

(Odziedziczone po ConfigurationElement)
LockItem

Pobiera lub ustawia wartość wskazującą, czy element jest zablokowany.

(Odziedziczone po ConfigurationElement)
Properties

Pobiera kolekcję właściwości.

(Odziedziczone po ConfigurationElement)
SectionInformation

Pobiera obiekt SectionInformation zawierający informacje i funkcje obiektu ConfigurationSection, które nie można dostosowywać.

(Odziedziczone po ConfigurationSection)

Metody

DeserializeElement(XmlReader, Boolean)

Odczytuje kod XML z pliku konfiguracji.

(Odziedziczone po ConfigurationElement)
DeserializeSection(XmlReader)

Odczytuje kod XML z pliku konfiguracji.

(Odziedziczone po ConfigurationSection)
Equals(Object)

Porównuje bieżące wystąpienie ConfigurationElement z określonym obiektem.

(Odziedziczone po ConfigurationElement)
GetHashCode()

Pobiera unikatową wartość reprezentującą bieżące wystąpienie ConfigurationElement.

(Odziedziczone po ConfigurationElement)
GetRuntimeObject()

Zwraca obiekt niestandardowy podczas zastępowania w klasie pochodnej.

(Odziedziczone po ConfigurationSection)
GetTransformedAssemblyString(String)

Zwraca przekształconą wersję określonej nazwy zestawu.

(Odziedziczone po ConfigurationElement)
GetTransformedTypeString(String)

Zwraca przekształconą wersję określonej nazwy typu.

(Odziedziczone po ConfigurationElement)
GetType()

Pobiera Type bieżącego wystąpienia.

(Odziedziczone po Object)
Init()

Ustawia obiekt ConfigurationElement na stan początkowy.

(Odziedziczone po ConfigurationElement)
InitializeDefault()

Służy do inicjowania domyślnego zestawu wartości dla obiektu ConfigurationElement.

(Odziedziczone po ConfigurationElement)
IsModified()

Wskazuje, czy ten element konfiguracji został zmodyfikowany od czasu ostatniego zapisania, czy załadowany podczas implementacji w klasie pochodnej.

(Odziedziczone po ConfigurationSection)
IsReadOnly()

Pobiera wartość wskazującą, czy obiekt ConfigurationElement jest tylko do odczytu.

(Odziedziczone po ConfigurationElement)
ListErrors(IList)

Dodaje błędy nieprawidłowej właściwości w tym obiekcie ConfigurationElement i we wszystkich elementach podrzędnych do przekazanej listy.

(Odziedziczone po ConfigurationElement)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Object.

(Odziedziczone po Object)
OnDeserializeUnrecognizedAttribute(String, String)

Pobiera wartość wskazującą, czy podczas deserializacji napotkano nieznany atrybut.

(Odziedziczone po ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

Pobiera wartość wskazującą, czy podczas deserializacji napotkano nieznany element.

(Odziedziczone po ConfigurationElement)
OnRequiredPropertyNotFound(String)

Zgłasza wyjątek, gdy nie można odnaleźć wymaganej właściwości.

(Odziedziczone po ConfigurationElement)
PostDeserialize()

Wywoływana po deserializacji.

(Odziedziczone po ConfigurationElement)
PreSerialize(XmlWriter)

Wywoływana przed serializacji.

(Odziedziczone po ConfigurationElement)
Reset(ConfigurationElement)

Resetuje stan wewnętrzny obiektu ConfigurationElement, w tym blokady i kolekcje właściwości.

(Odziedziczone po ConfigurationElement)
ResetModified()

Resetuje wartość metody IsModified(), aby false po zaimplementowaniu w klasie pochodnej.

(Odziedziczone po ConfigurationSection)
SerializeElement(XmlWriter, Boolean)

Zapisuje zawartość tego elementu konfiguracji w pliku konfiguracji po zaimplementowaniu w klasie pochodnej.

(Odziedziczone po ConfigurationElement)
SerializeSection(ConfigurationElement, String, ConfigurationSaveMode)

Tworzy ciąg XML zawierający niezaergowany widok obiektu ConfigurationSection jako pojedynczą sekcję do zapisu w pliku.

(Odziedziczone po ConfigurationSection)
SerializeToXmlElement(XmlWriter, String)

Zapisuje zewnętrzne tagi tego elementu konfiguracji do pliku konfiguracji po zaimplementowaniu w klasie pochodnej.

(Odziedziczone po ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

Ustawia właściwość na określoną wartość.

(Odziedziczone po ConfigurationElement)
SetReadOnly()

Ustawia właściwość IsReadOnly() dla obiektu ConfigurationElement i wszystkich podelementów.

(Odziedziczone po ConfigurationElement)
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName)

Wskazuje, czy określony element powinien być serializowany, gdy hierarchia obiektów konfiguracji jest serializowana dla określonej wersji docelowej programu .NET Framework.

(Odziedziczone po ConfigurationSection)
ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement)

Wskazuje, czy określona właściwość powinna być serializowana, gdy hierarchia obiektów konfiguracji jest serializowana dla określonej wersji docelowej programu .NET Framework.

(Odziedziczone po ConfigurationSection)
ShouldSerializeSectionInTargetVersion(FrameworkName)

Wskazuje, czy bieżące wystąpienie ConfigurationSection powinno być serializowane, gdy hierarchia obiektów konfiguracji jest serializowana dla określonej wersji docelowej programu .NET Framework.

(Odziedziczone po ConfigurationSection)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

Modyfikuje obiekt ConfigurationElement, aby usunąć wszystkie wartości, które nie powinny być zapisywane.

(Odziedziczone po ConfigurationElement)

Dotyczy

Zobacz też