You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET Web应用连接本地SQL数据库遇配置错误求助

解决“The configuration section 'connectionStrings' cannot be read because it is missing a section declaration”错误

你的错误由两个核心问题导致,修复步骤如下:

1. 修正connectionStrings节点位置

connectionStrings是<configuration>的直接子节点,不能嵌套在<system.web>内部。

2. 修正属性拼写错误

连接字符串的属性名应为connectionString(首字母S大写),你写的是小写的connectionstring,这会导致配置无法识别。

修复后的完整web.config代码

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
      <add name = "Milestone3"
         connectionString = "Data Source = (localdb)\MSSQLLocalDB;Initial Catalog=Milestone_2;Integrated Security=True"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=&quot;Web&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

额外检查项(若修复后仍有问题)

  • 确认项目目标框架与运行环境匹配:确保本地/IIS的.NET Framework 4.7.2已正确安装
  • 检查IIS应用程序池设置:将应用程序池的.NET CLR版本设为v4.0.x,托管管道模式选择集成模式
  • 验证LocalDB状态:打开命令提示符执行sqllocaldb info MSSQLLocalDB,若未启动则运行sqllocaldb start MSSQLLocalDB

内容的提问来源于stack exchange,提问作者Yahia Eid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 18:55:33