Configuration.ConnectionStrings Property
.NET Framework (current version)
Gets a ConnectionStringsSection configuration-section object that applies to this Configuration object.
Assembly: System.Configuration (in System.Configuration.dll)
Property Value
Type: System.Configuration.ConnectionStringsSectionA ConnectionStringsSection configuration-section object representing the connectionStrings configuration section that applies to this Configuration object.
Use the ConnectionStrings property to access and change the connectionStrings configuration section defined in the open configuration file.
The following code example demonstrates how to use the ConnectionStrings property.
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
.NET Framework
Available since 2.0
Available since 2.0
Show: