<appSettings>
<add key="strConn" value="Provider=SQLOLEDB;Data Source=(local);Initial Catalog=pubs;User ID=sa; password= "/>
</appSettings>

解决方案 »

  1.   

    what book are you reading? your code looks beta-ish, throw it away and buy a new book on asp.netyour web.config (not config.web) is invalid, also, xml is case-sensitive<configuration>
        <appSettings>
            <add key="strConn" value="server=localhost;uid=sa;pwd=;Database=pubs" />
        </appSettings>
    <system.web>
          <globalization requestEncoding="gb2312"
                   responseEncoding="gb2312"
                   fileEncoding="gb2312"
                   culture="zh-CN"
                   uiCulture="zh-CN"/>
       </system.web></configuration>
    test.aspx:<%@ Page Language="VB" Debug="true" %>
    <script runat="server">    Sub Page_Load(Sender As Object, E As EventArgs)
             Dim MyConnection As String
             Dim Config As NameValueCollection 
             Config = Context.GetConfig("appSettings")
             MyConnection = Config("strConn")    
             ' or use
    MyConnection = ConfigurationSettings.AppSettings("strConn")
             aa.Text = MyConnection
        End Sub</script>
    <html>
    <head>
    </head>
    <body>
        <xmp><asp:Label id="aa" runat="server"></asp:Label> dsadsa</xmp>
    </body>
    </html>
      

  2.   

    <configuration>
        <appSettings>      '出错(分析器错误信息:无法识别的配置节"appsettings")
            <add key="strConn" value="server=localhost;uid=sa;pwd=;Database=pubs" />
        </appSettings>
    <system.web>
          <globalization requestEncoding="gb2312"
                   responseEncoding="gb2312"
                   fileEncoding="gb2312"
                   culture="zh-CN"
                   uiCulture="zh-CN"/>
       </system.web></configuration>
      

  3.   

    are you sure? it is "appSettings", not "appsettings"what version of .NET do you have? I tested the code I posted earlier, it works well on .NET 1.1
      

  4.   

    可以了!
    "appSettings"和"appsettings"不同吗?
    ASP.NET是区分大小写的吗?
      

  5.   

    XML is case-sensitive and the class that reads the configuration file needs case-sensitive