出现问题的原因

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


在网上搜了一下,有说是数据库连接字符串错误的,有说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:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.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:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config 文件里。可能是这期间安装其他软件导致配置文件被修改。
解决办法:将machine.config用同在一个目录下的machine.config.default替换。

另:

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

【WinForm】“System.Data.SqlClient.SqlConnection”的类型初始值设定项引发异常,无法识别的配置节 system.serviceModel的更多相关文章

  1. “System.Data.SqlClient.SqlConnection”的类型初始值设定项引发异常---解决方案

    "System.Data.SqlClient.SqlConnection"的类型初始值设定项引发异常 问题出在了 .net 的C:\WINDOWS\Microsoft.NET\Fr ...

  2. “SYSTEM.DATA.SQLCLIENT.SQLCONNECTION”的类型初始值设定项引发异常---解决方案

    “System.Data.SqlClient.SqlConnection”的类型初始值设定项引发异常 问题出在了 .net 的C:\WINDOWS\Microsoft.NET\Framework\v2 ...

  3. System.Data.Entity.Internal.AppConfig 类型初始值设定项引发异常

    在一开始时将connectionStrings 写在了configSections之上如下图一示,结果抛出:“System.Data.Entity.Internal.AppConfig”的类型初始值设 ...

  4. “System.Transactions.Diagnostics.DiagnosticTrace”的类型初始值设定项引发异常[WCF]

    未处理System.TypeInitializationException  HResult=-2146233036  Message=“System.ServiceModel.Diagnostics ...

  5. “System.Transactions.Diagnostics.DiagnosticTrace”的类型初始值设定项引发异常。

    今天在项目中用log4net,App.config文件中增加了configSections节点,程序运行报错“System.Transactions.Diagnostics.DiagnosticTra ...

  6. 关于WPF System.windows.Media.FontFamily 的类型初始值设定项引发异常问题解决方法

    造成原因:此问题的根本原因是.NET Framework January 2018 Rollup(KB4055002)与已安装的.NET Framework 4.7.1产品版本之间的MSI安装交互.R ...

  7. 使用EF访问数据库,出现“System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常。

    今天在使用的EF时候,发生了"System.Data.Entity.Internal.AppConfig"的类型初始值设定项引发异常.这样的一个错误 查了原因,原来是appconf ...

  8. C#使用NLOG System.TypeInitializationException,类型初始值设定项引发异常

    C#如何使用NLOG,网上有很多介绍,本次使用时遇到一个问题,使用NLOG写日志时,出现初始化异常,基本异常信息如下: System.AggregateException: 发生一个或多个错误. -- ...

  9. Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache的类型初始值设定项引发异常。 ---> System.IO.FileLoadException: 未能加载文件或程序集

    场景: 安装程序到全新的环境的电脑时中(此时已经安装了能正常安装程序电脑的环境) 完整错误: Application_ThreadException:System.TypeInitialization ...

随机推荐

  1. Android 之 用WebView显示网页

    WebView可以使得网页轻松的内嵌到 app 里,还可以直接跟js相互调用. WebView有两个方法:setWebChromeClient 和 setWebClient (1) setWebCli ...

  2. 浅析jQuery中常用的元素查找方法总结

    本篇文章是对jQuery中常用的元素查找方法进行了详细的总结和介绍,需要的朋友参考下   $("#myELement") 选择id值等于myElement的元素,id值不能重复在文 ...

  3. ListView的addAll方法

    add是将传入的参数作为当前List中的一个Item存储,即使你传入一个List也只会另当前的List增加1个元素addAll是传入一个List,将此List中的所有元素加入到当前List中,也就是当 ...

  4. 2.1.6 用ProtectX实现扫描的反击与追踪

    ProtectX是一款在用户连接网络时保护电脑的工具,可以同时监视20个端口,还可以帮助追踪攻击者的来源.一旦有人尝试连接到用户的电脑,它即可发出声音警告并将入侵者的IP位址记录下来,可以防止黑客入侵 ...

  5. java如何判断字符串是否为空的方法

    以下是java 判断字符串是否为空的四种方法: 方法一: 最多人使用的一个方法, 直观, 方便, 但效率很低: if(s == null ||"".equals(s)); 方法二: ...

  6. 【开源项目8】Android开源项目分类汇总【畜生级别】

    欢迎大家推荐好的Android开源项目,可直接Commit或在 收集&提交页 中告诉我,欢迎Star.Fork :) 微博:Trinea    主页:www.trinea.cn    邮箱:t ...

  7. Ubuntu/Debian 安装lxml的正确方式

    lxml是Python的一个库,主要用于处理XML和HTML. 最近需要用lxml,但是在Ubuntu上直接pip安装失败,研究了半天终于找到了正确安装方法,记录在此. 由于Ubuntu和Debian ...

  8. js 每秒刷新系统时间,可停止

    <title>无标题页</title> <script language="javascript" type="text/javascrip ...

  9. 教您如何检查oracle死锁,决解死锁

    oracle死锁问题一直困扰着我们,下面就教您一个oracle死锁的检查方法,如果您之前遇到过oracle死锁方面的问题,不妨一看…… oracle死锁问题一直困扰着我们,下面就教您一个oracle死 ...

  10. 剑指Offer16 判断子树

    /************************************************************************* > File Name: 17_Mirror ...