2009-11-23 141 views
3

我一直在VS2005中使用本地連接訪問數據庫的項目。「無法識別的配置節connectionStrings」。

在過去的一週中,我安裝了.NET Framework 3.5,以用於不同的項目以及VS6。

我回到我的VS2005的應用程序,突然有很大的問題:

在設計任何類利用我的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.Dictionary 2.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, Dictionary 2 names) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.FillStatementTable(IDesignerSerializationManager manager, IDictionary table, Dictionary 2 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)

而當我跑的應用程序,我遇到以下異常啓動時:

"Unrecognized configuration section connectionStrings."

在網上找,這些問題似乎普遍涉及到建在VS2005的東西和部署.NET 1.1框架;但是這全部作爲VS本地內的Windows窗體應用程序運行(不在IIS上)。我試過卸載並重新安裝VS2K5無濟於事。

有什麼想法? 謝謝, 馬特

回答

5

這是胡亂猜測......但我想我的時候你有< configSections在你的web.config >元素之前,一些之前已經看到了這個。例如,這將導致一個錯誤:

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

的<configSections>元素需要是第一位的:

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

也許不是什麼導致你的問題,但我想我會提到它...

+0

感謝您的答覆! 我不相信這是這種情況,我的app.config如下: <?xml version =「1.0」encoding =「utf-8」?> <結構> 節點 <添加名稱= 「Mockups.Properties.Settings.MockupDSConnectionString」 的connectionString =「提供商= Microsoft.Jet.OLEDB.4.0;數據源= | DataDirectory | \ MockupDS.mdb「 providerName =」System.Data.OleDb「/> 2009-11-24 14:03:59

+0

我認爲存在某些配置錯誤 - 不幸的是,卸載/安裝的東西似乎無法解決它。 即使我嘗試創建一個新的DataSource連接 - 在連接嚮導中 - 我選擇OLE DB連接,選擇.mdb,然後單擊「確定」,彈出窗口顯示「目標拋出了異常的調用。「就是這樣! 非常令人沮喪...... – 2009-11-24 14:04:36

+0

我正在敲我的腦袋,試圖找出爲什麼我的App.config不適用於某些自定義類型 - 這是問題所在。謝謝! – dmo 2010-03-25 19:49:41

0

我一直面臨同樣的問題。請檢查您的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"/> 

,當我刪除了

..system.windows.forms jitDebugging="true"/>

再次工作得很好..

7

這是真的老了後,我知道,但我最近有同樣的問題,我有

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

所以我的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> 

在C#中,我使用下面的代碼來獲取我的連接字符串:

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

這適用於我,雖然appSettings部分不是必需的(除非您在配置中使用它) – MatthewC 2015-02-02 04:20:33

相關問題