I\'ve got a reference to System.Configuration
- and ConfigurationSettings
is found no problem - but the type or namespace \'ConfigurationMana
You need to use the System Configuration namespace, this must be included in two ways:
Right click the project and choose add reference, browse "Assemblies" and tick the System.Configuration assembly.
Include the namespace in code:
using System.Configuration;
ConfigurationManager is a part of the System.Configuration after .Net 2.0. Add a reference to the System.Configuration dll. Try using System.Configuration.ConfigurationManager.
You need to add a reference the System.Configuration assembly. This namespace was split across a few assemblies.
I'm working in VisualStudio 2015, and ConfigurationManager
is not present at System.Configuration
namespace anymore.
I was just trying to read the App.config file...
Then I found a solution:
Get:
string str = MyProjectNamespace.Properties.Settings.Default["MySettingName"].ToString();
Set:
MyProjectNamespace.Properties.Settings.Default["MySettingName"]="myString";
MyProjectNamespace.Properties.Settings.Default.Save();
For me, this problem was solved when I put the "BuildConnectionString" function in a class and added "Imports System.Configuration" at the top of the class page. I did as the Microsoft site itself says. https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-builders
Private Sub BuildConnectionString(ByVal dataSource As String, _
ByVal userName As String, ByVal userPassword As String)
' Retrieve the partial connection string named databaseConnection
' from the application's app.config or web.config file.
Dim settings As ConnectionStringSettings = _
ConfigurationManager.ConnectionStrings("partialConnectString")
If Not settings Is Nothing Then
' Retrieve the partial connection string.
Dim connectString As String = settings.ConnectionString
Console.WriteLine("Original: {0}", connectString)
' Create a new SqlConnectionStringBuilder based on the
' partial connection string retrieved from the config file.
Dim builder As New SqlConnectionStringBuilder(connectString)
' Supply the additional values.
builder.DataSource = dataSource
builder.UserID = userName
builder.Password = userPassword
Console.WriteLine("Modified: {0}", builder.ConnectionString)
End If
End Sub
The important point is to use the function in the class. When I did this the error failed to find the source.
You will need to add the System.Configuration reference under the Reference folder in your project. Only adding the system.configuration with the using statement in your class is not enough.