visual-studio “无法识别的配置部分 connectionStrings。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1785437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Unrecognized configuration section connectionStrings."
提问by Matty U
I had been working on a project in VS2005 that utilized a local connection to an Access DB.
我一直在 VS2005 中从事一个项目,该项目利用到 Access DB 的本地连接。
In the past week, I installed .NET framework 3.5 for use w/ a different project as well as VS6.
在过去的一周中,我安装了 .NET framework 3.5 以用于不同的项目以及 VS6。
I went back to my VS2005 application and suddenly there are big issues:
我回到我的 VS2005 应用程序,突然出现了大问题:
In the designer for any class utilizing my OLEDB connection showed this:
在使用我的 OLEDB 连接的任何类的设计器中都显示了这一点:
Unable to cast object of type 'System.Configuration.DefaultSection' to type 'System.Configuration.ConnectionStringsSection'. Hide
at System.Configuration.Configuration.get_ConnectionStrings() at Microsoft.VisualStudio.Shell.Design.Serialization.ConfigurationHelperService.ReadConnectionStrings(String configFileName, DocData configDocData, String prefix) at Microsoft.VisualStudio.Editors.SettingsDesigner.AppConfigSerializer.Deserialize(DesignTimeSettings Settings, String SectionName, DocData AppConfigDocData, MergeValueMode mergeMode, IUIService UIService) at Microsoft.VisualStudio.Editors.SettingsGlobalObjects.SettingsFileGlobalObject.LoadSettings(String fileName) at Microsoft.VisualStudio.Editors.SettingsGlobalObjects.SettingsFileGlobalObject.BuildType() at Microsoft.VisualStudio.Editors.SettingsGlobalObjects.SettingsFileGlobalObject.GetObjectType() at Microsoft.VisualStudio.Shell.Design.GlobalType.get_ObjectType() at Microsoft.VisualStudio.Shell.Design.GlobalObject.GetHashCode() at Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GlobalKey.GetHashCode() at System.Collections.Generic.ObjectEqualityComparer
1.GetHashCode(T obj) at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GetGlobalObjects(Type baseType) at Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GetGlobalObjects() at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetTypeFromGlobalObjects(String name, Boolean throwOnError, Boolean ignoreCase) at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase) at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.GetType(ITypeResolutionService trs, String name, Dictionary2 names) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.FillStatementTable(IDesignerSerializationManager manager, IDictionary table, Dictionary2 names, CodeStatementCollection statements, String className) at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration) at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
无法将“System.Configuration.DefaultSection”类型的对象转换为“System.Configuration.ConnectionStringsSection”类型。隐藏
在 System.Configuration.Configuration.get_ConnectionStrings() 在 Microsoft.VisualStudio.Shell.Design.Serialization.ConfigurationHelperService.ReadConnectionStrings(String configFileName, DocData configDocData, String prefix) 在 Microsoft.VisualStudio.Editors.SettingsDesigner.AppConfigSerializer.Deserialize(DesignTimeSettings Settings, String SectionName, DocData AppConfigDocData, MergeValueMode mergeMode, IUIService UIService) at Microsoft.VisualStudio.Editors.SettingsGlobalObjects.SettingsFileGlobalObject.LoadSettings(String fileName) at Microsoft.VisualStudio.Editors.SettingsGlobalObjects.SettingsFileGlobalObject.BuildType() at Microsoft.VisualStudio.Editors.SettingsGlobalObjects .SettingsFileGlobalObject.GetObjectType() 在 Microsoft.VisualStudio.Shell.Design.GlobalType.get_ObjectType() 在 Microsoft.VisualStudio.Shell。Design.GlobalObject.GetHashCode() 在 Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GlobalKey.GetHashCode() 在 System.Collections.Generic.ObjectEqualityComparer
1.GetHashCode(T obj) at System.Collections.Generic.Dictionary2.FindEntry(TKey 键) 在 Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GetGlobalObjects(Type baseType) 在 Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GetGlobalObjects() 在 Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService。 GetTypeFromGlobalObjects(String name, Boolean throwOnError, Boolean ignoreCase) 在 Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase) 在 Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(字符串名称,布尔 throwOnError) 在 System.ComponentModel.Design.Serialization.CodeDomSerializerBase.GetType(ITypeResolutionService trs,字符串名称,字典2 names) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.FillStatementTable(IDesignerSerializationManager manager, IDictionary table, Dictionary2 个名称,CodeStatementCollection 语句,String className) 在 System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration) at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager) at Microsoft.VisualStudio.Design .Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) 在 Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
And when I ran the app, I encounter the following exception on startup:
当我运行应用程序时,我在启动时遇到以下异常:
"Unrecognized configuration section connectionStrings."
“无法识别的配置部分 connectionStrings。”
In looking online, these issues seem to commonly relate to things built in VS2005 and deployed on .net 1.1 framework; but this is all running as a windows forms application locally within VS (not on IIS). I've tried uninstalling and reinstalling VS2K5 to no avail.
在网上查看,这些问题似乎通常与 VS2005 中构建并部署在 .net 1.1 框架上的东西有关;但这一切都作为 Windows 窗体应用程序在 VS 本地运行(不在 IIS 上)。我试过卸载并重新安装 VS2K5 无济于事。
Any thoughts? Thanks, Matt
有什么想法吗?谢谢,马特
回答by Vin.X
This is a really old post, i know, but i have had the same problem recently, i have fixed it by putting:
这是一个非常老的帖子,我知道,但我最近遇到了同样的问题,我通过以下方式修复了它:
<configSections>
<section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>
<section name="connectionStrings" type="System.Configuration.ConnectionStringsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false"/>
<configSections>
before my connection strings:
在我的连接字符串之前:
<connectionStrings>
<add name="XXX" connectionString="Data Source=.;Initial Catalog=db;User Id=user;Password=pw;" providerName="System.Data.SqlClient"/>
</connectionStrings>
so my app.config looks like:
所以我的 app.config 看起来像:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>
<section name="connectionStrings" type="System.Configuration.ConnectionStringsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false"/>
<configSections>
<connectionStrings>
<add name="XXX" connectionString="Data Source=.;Initial Catalog=db;User Id=user;Password=pw;" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
In C# I am using below code to retrieve my connection string:
在 C# 中,我使用下面的代码来检索我的连接字符串:
ConfigurationFileMap fileMap = new ConfigurationFileMap("myApp.config"); //Path to your config file
Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
this.connectionString = configuration.ConnectionStrings.ConnectionStrings["XXX"].ConnectionString;
回答by Richard Beier
This is a wild guess... but I think I've seen this before when you have something before the <configSections> element in your web.config. For example, this would cause an error:
这是一个疯狂的猜测......但我想我以前见过这个,当你在你的 web.config 中的 <configSections> 元素之前有一些东西。例如,这会导致错误:
<configuration>
<connectionStrings [...] />
<configSections>
<sectionGroup name=[...] />
</configSections>
</configuration>
The <configSections> element needs to come first:
<configSections> 元素需要先出现:
<configuration>
<configSections>
<sectionGroup name=[...] />
</configSections>
<connectionStrings [...] />
</configuration>
Probably not what's causing your problem but I thought I'd mention it...
可能不是导致您问题的原因,但我想我会提到它...
回答by Neeraj Lohumi
i had been facing the same issue.please check your machine.config file.
我遇到了同样的问题。请检查您的 machine.config 文件。
<configuration>
<system.windows.forms jitDebugging="true"/>
<configSections>
<section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>
<section name="connectionStrings" type="System.Configuration.ConnectionStringsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false"/>
and when i removed the
当我删除
..system.windows.forms jitDebugging="true"/>
..system.windows.forms jitDebugging="true"/>
it again worked fine..
它再次工作正常..

