Configuration.ConnectionStrings Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene un objeto de sección de configuración ConnectionStringsSection que se aplica a este objeto 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
Valor de propiedad
Objeto de sección de configuración ConnectionStringsSection que representa la sección de configuración connectionStrings
que se aplica a este objeto Configuration.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar la ConnectionStrings propiedad .
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
Comentarios
Use la ConnectionStrings propiedad para acceder a la sección de configuración definida en el archivo de configuración abierto y cambiarla connectionStrings
.