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#
    向我打赏
    加我微信,聊一聊技术
  • 相关阅读:
    linux下硬盘分区、格式化以及文件管理系统
    linux下的文档处理及tar命令
    linux文件及目录的权限管理
    linux用户和群组
    linux下mysql的安装与使用
    linux上uwsgi+nginx+django发布项目
    linux虚拟环境搭建
    linux目录文件操作
    linux基本命令
    rbac组件之权限初始化(五)
  • 原文地址:https://www.cnblogs.com/mzy-google/p/5193431.html
Copyright © 2011-2022 走看看