Where is ConfigurationManager's namespace?

后端 未结 7 1130
半阙折子戏
半阙折子戏 2021-01-01 09:43

I\'ve got a reference to System.Configuration - and ConfigurationSettings is found no problem - but the type or namespace \'ConfigurationMana

7条回答
  •  再見小時候
    2021-01-01 10:09

    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.

提交回复
热议问题