配置系统初始化失败 [英] Configuration System Failed to Initialize
问题描述
我是 Visual Studio 的新手.我目前正在创建一个登录表单.
I'm new to Visual Studio. I'm currently creating a Login form.
我有这个代码.
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
try
{
using (OdbcConnection connect = new OdbcConnection(connectionString))
{
connect.Open();
OdbcCommand cmd = new OdbcCommand("SELECT username, password FROM receptionist", connect);
OdbcDataReader reader = cmd.ExecuteReader();
if (username_login.Text == username && password_login.Text == password)
{
this.Hide();
MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
else
MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
connect.Close();
}
}
catch (OdbcException ex)
{
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
但是每当我尝试输入用户名和密码时,都会出现一个名为配置系统初始化失败的错误.我只是想知道这是什么问题,我该如何解决?
But whenever I try to type in the username and password there is an error called Configuration system failed to initialize. I'm just wondering what kind of problem is this and how could I solve this?
请帮忙.
推荐答案
确保你的项目中的配置文件(web.config 如果是 web,或者 app.config 如果是 windows)启动为:
Make sure that your config file (web.config if web, or app.config if windows) in your project starts as:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="YourProjectName.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
</configuration>
请注意,在 configuration
元素中,第一个子元素必须是 configSections
元素.
Note that inside the configuration
element, the first child must be the configSections
element.
在 section
元素的 name
属性中,确保替换了 YourProjectName
使用您的实际项目名称.
In the name
property on section
element, make sure you replace YourProjectName
with your actual project's name.
碰巧我在类库项目中创建了一个 webservice,然后我将配置文件(为了带来端点配置)复制(覆盖)到我的 Windows 应用程序,我开始遇到同样的问题.我无意中删除了 configSections
.
It happened to me that I created a webservice in a class library project, then I copied (overwriting) the config file (in order to bring the endpoints configuration) to my windows app and I started to have the same problem. I had inadvertently removed configSections
.
对我有用,希望能帮到你
it worked for me, hope it helps
这篇关于配置系统初始化失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!