zoukankan      html  css  js  c++  java
  • 【WinForm】“System.Data.SqlClient.SqlConnection”的类型初始值设定项引发异常,无法识别的配置节 system.serviceModel

    出现问题的原因

    在本机上没有出现问题,让一个同事测试的时候,在另外一台电脑上出现连接数据库失败,系统不能打开的问题


    在网上搜了一下,有说是数据库连接字符串错误的,有说app.config文件配置不匹配等原因的。总之是没有解决这个问题

    出现问题的错误信息,不全,只给出了主要的信息:如下

    错误描述:Void .ctor()
    System.TypeInitializationException: “System.Data.SqlClient.SqlConnection”的类型初始值设定项引发异常。 ---> System.TypeInitializationException: “System.Data.SqlClient.SqlConnectionFactory”的类型初始值设定项引发异常。 ---> System.TypeInitializationException: “System.Data.SqlClient.SqlPerformanceCounters”的类型初始值设定项引发异常。 ---> System.Configuration.ConfigurationErrorsException: 配置系统未能初始化 ---> System.Configuration.ConfigurationErrorsException: 无法识别的配置节 system.serviceModel。 (C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Configmachine.config line 146)
       在 System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
       在 System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
       在 System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
       在 System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       --- 内部异常堆栈跟踪的结尾 ---
       在 System.Configuration.ConfigurationManager.PrepareConfigSystem()
       在 System.Configuration.ConfigurationManager.GetSection(String sectionName)
       在 System.Configuration.ConfigurationManager.get_AppSettings()
       在 log4net.Util.SystemInfo.GetAppSetting(String key)
       --- 内部异常堆栈跟踪的结尾 ---
       在 System.Data.SqlClient.SqlConnectionFactory..cctor()
       --- 内部异常堆栈跟踪的结尾 ---
       在 System.Data.SqlClient.SqlConnection..cctor()
       --- 内部异常堆栈跟踪的结尾 ---
       在 System.Data.SqlClient.SqlConnection..ctor()
       在 System.Data.SqlClient.SqlConnection..ctor(String connectionString)

    在machine.config的文件里面的serviceModel信息如下:

    <system.serviceModel>
        <extensions>
          <behaviorExtensions>
            <add name="persistenceProvider" type="System.ServiceModel.Configuration.PersistenceProviderElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="workflowRuntime" type="System.ServiceModel.Configuration.WorkflowRuntimeElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="enableWebScript" type="System.ServiceModel.Configuration.WebScriptEnablingElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="webHttp" type="System.ServiceModel.Configuration.WebHttpElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          </behaviorExtensions>
          <bindingElementExtensions>
            <add name="webMessageEncoding" type="System.ServiceModel.Configuration.WebMessageEncodingElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="context" type="System.ServiceModel.Configuration.ContextBindingElementExtensionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          </bindingElementExtensions>
          <bindingExtensions>
            <add name="wsHttpContextBinding" type="System.ServiceModel.Configuration.WSHttpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="netTcpContextBinding" type="System.ServiceModel.Configuration.NetTcpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="webHttpBinding" type="System.ServiceModel.Configuration.WebHttpBindingCollectionElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="basicHttpContextBinding" type="System.ServiceModel.Configuration.BasicHttpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          </bindingExtensions>
        </extensions>
        <client>
          <metadata>
            <policyImporters>
              <extension type="System.ServiceModel.Channels.ContextBindingElementImporter, system.workflowservices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
            </policyImporters>
            <wsdlImporters>
              <extension type="System.ServiceModel.Channels.ContextBindingElementImporter, system.workflowservices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
            </wsdlImporters>
          </metadata>
        </client>
      </system.serviceModel>

    不知道这个信息的作用是什么。

    解决方法

    问题应该处在了 .net 的C:WINDOWSMicrosoft.NETFrameworkv2.0.50727CONFIGmachine.config 文件里。可能是这期间安装其他软件导致配置文件被修改。
    解决办法:将machine.config用同在一个目录下的machine.config.default替换。

    另:

    还有人给出这样的解决方法,没有试过,各位遇到这种问题可以自己试一下是否可行

    作者:芝麻科技
    出处:芝麻麻雀-Asp.Net学习之路
    技术:C++,C#
    向我打赏
    加我微信,聊一聊技术
  • 相关阅读:
    如何在Eclipse中查看Java类库的源代码以及相应的api
    深入剖析ConcurrentHashMap
    Java7/8 中的 HashMap 和 ConcurrentHashMap 全解析
    Quartz配置
    Spring 自动定时任务配置
    @Resource注解的官方解释
    @Resource 注解的使用
    扫地机器人会否抛弃激光雷达这位原配?
    女教授领军打造最耐用机器人,可从180米高空落下执行救援任务
    一文看懂80年“AI革命”简史
  • 原文地址:https://www.cnblogs.com/mzy-google/p/5193431.html
Copyright © 2011-2022 走看看