尝试在设计器中打开一些表单时发生错误。VS2015 Designer错误:appSettings配置部分中不存在键'Main.ConnectionString'
这是堆栈跟踪:
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
这里是我的app.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="Main.ConnectionString" value="Server=localhost;Database=ACTUAL_DB_NAME_HERE;User ID=ACTUAL_USER;Password=ACTUAL_PASSWORD;"/>
</appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
我认为这可能与数据以某种方式序列化在窗体控件中。 – scotru
我在2010年使用数据库图时遇到了类似的问题。它在大多数情况下都能很好地与配置文件一起工作('System.Configuration.ConfigurationManager.ConnectionStrings [“dbConnString”] .ConnectionString'),但取决于我如何运行代码,这会造成麻烦。通过在设置文件中添加字符串并使用'BaseClass.Properties.Settings.Default.DBConnString'访问它,我获得了更大的成功。这可能会帮助你吗? – Heki
在我的情况下,字符串(我相信)正在从我的ORM库进行访问。我没有在任何地方直接从我的代码访问字符串 - 但我的表单上有ORM对象。 – scotru