将 appSettings 值分配给字符串

Assigning appSettings values to a String

我收到一个错误。我正在尝试使用此 appSettings 连接到 SQL 服务器。但是这段代码给出了一个错误。

警告 6 'Public Shared ReadOnly Property AppSettings As System.Collections.Specialized.NameValueCollection' 已过时:'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'。

`

Public Class clsDL

    'Fields - Data
    Private adp As SqlDataAdapter
    Private cmd As SqlCommand
    Private Cn As SqlConnection
    Private Shared db As clsDL
    Private dr As SqlDataReader
    Private ds As DataSet
    Private dt As DataTable
    Private gUserPwdSeed As Object = 10
    Private intIndex As Integer
    Private m_trans As SqlTransaction
    Private objConSettings As ConfigurationSettings
    Private strCnString As String
    Private strDatabase As String
    Private strPwd As String
    Private strServer As String
    Private strUID As String


    Private Sub Connect()
        Try
            Me.strServer = ConfigurationSettings.AppSettings("Server")
            Me.strDatabase = ConfigurationSettings.AppSettings("Database")
            Me.strUID = ConfigurationSettings.AppSettings("UID")

    End Sub`

使用警告中的建议。

Private Sub Connect()
    Try
        Me.strServer = System.Configuration.ConfigurationManager.AppSettings("Server")
        Me.strDatabase = System.Configuration.ConfigurationManager.AppSettings("Database")
        Me.strUID = System.Configuration.ConfigurationManager.AppSettings("UID")

End Sub`

我们从旧代码库中采用了这种简单的方法,同时进行了转换而不是重写,并且效果很好。