ConnectionStringSettings Klass

Definition

Representerar en enda med namnet reťazec pripojenia i avsnittet konfigurationsfil för anslutningssträngar.

public ref class ConnectionStringSettings sealed : System::Configuration::ConfigurationElement
public sealed class ConnectionStringSettings : System.Configuration.ConfigurationElement
type ConnectionStringSettings = class
    inherit ConfigurationElement
Public NotInheritable Class ConnectionStringSettings
Inherits ConfigurationElement
Arv
ConnectionStringSettings

Exempel

I följande exempel visas hur du kommer åt ett ConnectionStringSettings objekt i ett visst index i en ConnectionStringSettingsCollection samling.

using System;
using System.Configuration;
using System.Web.Configuration;

namespace ConfigurationStringSettings
{
    class ConfigurationStringSettings
    {
        static void DisplayConnectionStrings()
        {
            // Set the path of the config file.
            // Make sure that you have a Web site on the
            // same server called TestConfig. 
            string configPath = "/TestConfig";

            // Get the Web application configuration object.
            Configuration config =
              WebConfigurationManager.OpenWebConfiguration(configPath);

            // Get the conectionStrings section.
            ConnectionStringsSection csSection =
                config.ConnectionStrings;

            Console.WriteLine("Display configuration strings.");

            for (int i = 0; i <
                ConfigurationManager.ConnectionStrings.Count; i++)
            {
                ConnectionStringSettings cs =
                    csSection.ConnectionStrings[i];

                Console.WriteLine("  Connection String: \"{0}\"",
                    cs.ConnectionString);

                Console.WriteLine("#{0}", i);
                Console.WriteLine("  Name: {0}", cs.Name);

                Console.WriteLine("  Provider Name: {0}",
                    cs.ProviderName);
            }
        }

        static void Main(string[] args)
        {
            try
            {   // Display connection strings.
                DisplayConnectionStrings();
            }
            catch (Exception e)
            {
                // Unknown error.
                Console.WriteLine(e.ToString());
            }

            // Display and wait.
            Console.WriteLine("Enter any key to exit.");
            Console.ReadLine();
        }
    }
}
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Web.Configuration
Imports System.Collections
Imports System.Text


Namespace ConfigurationStringSettings

    Class ConfigurationStringSettings

        Shared Sub DisplayConnectionStrings()
            ' Set the path of the config file.
            ' Make sure that you have a Web site on the
            ' same server called TestConfig. 
            Dim configPath As String = "/TestConfig"

            ' Get the Web application configuration object.
            Dim config As Configuration = _
            WebConfigurationManager.OpenWebConfiguration(configPath)


            ' Get the conectionStrings section.
            Dim csSection As ConnectionStringsSection = _
            config.ConnectionStrings

            Console.WriteLine("Display configuration strings.")

            Dim i As Integer = 0
            While i < ConfigurationManager.ConnectionStrings.Count
                Dim cs As ConnectionStringSettings = _
                csSection.ConnectionStrings(i)

                Console.WriteLine("  Connection String: ""{0}""", _
                                  cs.ConnectionString)

                Console.WriteLine("#{0}", i)
                Console.WriteLine("  Name: {0}", cs.Name)

                Console.WriteLine("  Provider Name: {0}", cs.ProviderName)
                System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
            End While

        End Sub


        Shared Sub Main(ByVal args As String())
            Try
                ' Display connection strings.
                DisplayConnectionStrings()
            Catch e As Exception
                ' Unknown error.
                Console.WriteLine(e.ToString())
            End Try

            ' Display and wait.
            Console.WriteLine("Enter any key to exit.")
            Console.ReadLine()
        End Sub
    End Class
End Namespace

Kommentarer

Ett ConnectionStringSettings objekt representerar en enda post i avsnittet konfigurationsfil connectionStrings .

Konstruktorer

Name Description
ConnectionStringSettings()

Initierar en ny instans av ConnectionStringSettings klassen.

ConnectionStringSettings(String, String, String)

Initierar en ny instans av ConnectionStringSettings klassen.

ConnectionStringSettings(String, String)

Initierar en ny instans av ConnectionStringSettings klassen.

Egenskaper

Name Description
ConnectionString

Hämtar eller anger reťazec pripojenia.

CurrentConfiguration

Hämtar en referens till den översta instansen Configuration som representerar konfigurationshierarkin som den aktuella ConfigurationElement instansen tillhör.

(Ärvd från ConfigurationElement)
ElementInformation

Hämtar ett ElementInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationElement objektet.

(Ärvd från ConfigurationElement)
ElementProperty

Hämtar objektet ConfigurationElementProperty som representerar ConfigurationElement själva objektet.

(Ärvd från ConfigurationElement)
EvaluationContext

Hämtar ContextInformation-objektet för ConfigurationElement-objektet.

(Ärvd från ConfigurationElement)
HasContext

Hämtar ett värde som anger om egenskapen CurrentConfiguration är null.

(Ärvd från ConfigurationElement)
Item[ConfigurationProperty]

Hämtar eller anger en egenskap eller ett attribut för det här konfigurationselementet.

(Ärvd från ConfigurationElement)
Item[String]

Hämtar eller anger en egenskap, ett attribut eller ett underordnat element i det här konfigurationselementet.

(Ärvd från ConfigurationElement)
LockAllAttributesExcept

Hämtar samlingen med låsta attribut.

(Ärvd från ConfigurationElement)
LockAllElementsExcept

Hämtar samlingen med låsta element.

(Ärvd från ConfigurationElement)
LockAttributes

Hämtar samlingen med låsta attribut.

(Ärvd från ConfigurationElement)
LockElements

Hämtar samlingen med låsta element.

(Ärvd från ConfigurationElement)
LockItem

Hämtar eller anger ett värde som anger om elementet är låst.

(Ärvd från ConfigurationElement)
Name

Hämtar eller anger ConnectionStringSettings namnet.

Properties

Hämtar samlingen med egenskaper.

(Ärvd från ConfigurationElement)
ProviderName

Hämtar eller anger egenskapen providernamn.

Metoder

Name Description
DeserializeElement(XmlReader, Boolean)

Läser XML från konfigurationsfilen.

(Ärvd från ConfigurationElement)
Equals(Object)

Jämför den aktuella ConfigurationElement instansen med det angivna objektet.

(Ärvd från ConfigurationElement)
GetHashCode()

Hämtar ett unikt värde som representerar den aktuella ConfigurationElement instansen.

(Ärvd från ConfigurationElement)
GetTransformedAssemblyString(String)

Returnerar den transformerade versionen av det angivna sammansättningsnamnet.

(Ärvd från ConfigurationElement)
GetTransformedTypeString(String)

Returnerar den transformerade versionen av det angivna typnamnet.

(Ärvd från ConfigurationElement)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
Init()

Anger objektets ConfigurationElement ursprungliga tillstånd.

(Ärvd från ConfigurationElement)
InitializeDefault()

Används för att initiera en standarduppsättning med värden för ConfigurationElement objektet.

(Ärvd från ConfigurationElement)
IsModified()

Anger om det här konfigurationselementet har ändrats sedan det senast sparades eller lästes in när det implementerades i en härledd klass.

(Ärvd från ConfigurationElement)
IsReadOnly()

Hämtar ett värde som anger om objektet ConfigurationElement är skrivskyddat.

(Ärvd från ConfigurationElement)
ListErrors(IList)

Lägger till felen invalid-property i det här ConfigurationElement objektet, och i alla underelement, i den överförda listan.

(Ärvd från ConfigurationElement)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
OnDeserializeUnrecognizedAttribute(String, String)

Hämtar ett värde som anger om ett okänt attribut påträffas under deserialiseringen.

(Ärvd från ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

Hämtar ett värde som anger om ett okänt element påträffas under deserialiseringen.

(Ärvd från ConfigurationElement)
OnRequiredPropertyNotFound(String)

Utlöser ett undantag när en obligatorisk egenskap inte hittas.

(Ärvd från ConfigurationElement)
PostDeserialize()

Anropas efter deserialisering.

(Ärvd från ConfigurationElement)
PreSerialize(XmlWriter)

Anropas före serialisering.

(Ärvd från ConfigurationElement)
Reset(ConfigurationElement)

Återställer objektets interna tillstånd ConfigurationElement , inklusive låsen och egenskapssamlingarna.

(Ärvd från ConfigurationElement)
ResetModified()

Återställer värdet för metoden till false när den IsModified() implementeras i en härledd klass.

(Ärvd från ConfigurationElement)
SerializeElement(XmlWriter, Boolean)

Skriver innehållet i det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass.

(Ärvd från ConfigurationElement)
SerializeToXmlElement(XmlWriter, String)

Skriver de yttre taggarna för det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass.

(Ärvd från ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

Anger en egenskap till det angivna värdet.

(Ärvd från ConfigurationElement)
SetReadOnly()

Anger egenskapen IsReadOnly() för ConfigurationElement objektet och alla underelement.

(Ärvd från ConfigurationElement)
ToString()

Returnerar en strängrepresentation av objektet.

Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

Ändrar objektet ConfigurationElement för att ta bort alla värden som inte ska sparas.

(Ärvd från ConfigurationElement)

Gäller för

Se även