Configuration.ConnectionStrings Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient un objet de section de configuration ConnectionStringsSection qui s'applique à cet objet Configuration.
public:
property System::Configuration::ConnectionStringsSection ^ ConnectionStrings { System::Configuration::ConnectionStringsSection ^ get(); };
public System.Configuration.ConnectionStringsSection ConnectionStrings { get; }
member this.ConnectionStrings : System.Configuration.ConnectionStringsSection
Public ReadOnly Property ConnectionStrings As ConnectionStringsSection
Valeur de propriété
Objet de section de configuration ConnectionStringsSection représentant la section de configuration connectionStrings
qui s'applique à cet objet Configuration.
Exemples
L’exemple de code suivant montre comment utiliser la ConnectionStrings propriété .
ConnectionStringsSection
conStrSection =
config.ConnectionStrings as ConnectionStringsSection;
Console.WriteLine("Section name: {0}",
conStrSection.SectionInformation.SectionName);
try
{
if (conStrSection.ConnectionStrings.Count != 0)
{
Console.WriteLine();
Console.WriteLine("Using ConnectionStrings property.");
Console.WriteLine("Connection strings:");
// Get the collection elements.
foreach (ConnectionStringSettings connection in
conStrSection.ConnectionStrings)
{
string name = connection.Name;
string provider = connection.ProviderName;
string connectionString = connection.ConnectionString;
Console.WriteLine("Name: {0}",
name);
Console.WriteLine("Connection string: {0}",
connectionString);
Console.WriteLine("Provider: {0}",
provider);
}
}
}
catch (ConfigurationErrorsException e)
{
Console.WriteLine("Using ConnectionStrings property: {0}",
e.ToString());
}
Dim conStrSection As ConnectionStringsSection = TryCast(config.ConnectionStrings, ConnectionStringsSection)
Console.WriteLine("Section name: {0}", conStrSection.SectionInformation.SectionName)
Try
If conStrSection.ConnectionStrings.Count <> 0 Then
Console.WriteLine()
Console.WriteLine("Using ConnectionStrings property.")
Console.WriteLine("Connection strings:")
' Get the collection elements.
For Each connection As ConnectionStringSettings In conStrSection.ConnectionStrings
Dim name As String = connection.Name
Dim provider As String = connection.ProviderName
Dim connectionString As String = connection.ConnectionString
Console.WriteLine("Name: {0}", name)
Console.WriteLine("Connection string: {0}", connectionString)
Console.WriteLine("Provider: {0}", provider)
Next connection
End If
Catch e As ConfigurationErrorsException
Console.WriteLine("Using ConnectionStrings property: {0}", e.ToString())
End Try
Remarques
Utilisez la ConnectionStrings propriété pour accéder et modifier la section de connectionStrings
configuration définie dans le fichier de configuration ouvert.