English 中文(简体)
"Unrecognized configuration section connectionStrings."
原标题:

I had been working on a project in VS2005 that utilized a local connection to an Access DB.

In the past week, I installed .NET framework 3.5 for use w/ a different project as well as VS6.

I went back to my VS2005 application and suddenly there are big issues:

In the designer for any class utilizing my OLEDB connection showed this:

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.ObjectEqualityComparer1.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)

And when I ran the app, I encounter the following exception on startup:

"Unrecognized configuration section 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.

Any thoughts? Thanks, Matt

问题回答

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:

<?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:

ConfigurationFileMap fileMap = new ConfigurationFileMap("myApp.config"); //Path to your config file
Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
this.connectionString = configuration.ConnectionStrings.ConnectionStrings["XXX"].ConnectionString;

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:

<configuration>
  <connectionStrings [...] />
  <configSections>
    <sectionGroup name=[...] />
  </configSections>
</configuration>

The <configSections> element needs to come first:

<configuration>
  <configSections>
    <sectionGroup name=[...] />
  </configSections>
  <connectionStrings [...] />
</configuration>

Probably not what s causing your problem but I thought I d mention it...

i had been facing the same issue.please check your machine.config file.

<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"/>

it again worked fine..

It was the camelCase issue in my case. Both <connectionStrings> and <connectionstrings> work but it should be the same in the section name and within connection string itself.

  <connectionStrings>
    <add name="default"
         connectionString=[...] />
  </connectionStrings>




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签