我是 Visual Studio 的新手。我目前正在创建一个登录表单。
我有这个代码。
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);
}
但是每当我尝试输入用户名和密码时,都会出现一个名为配置系统初始化失败的错误。我只是想知道这是什么问题,我该如何解决?
请帮忙。
最佳答案
确保项目中的配置文件(如果是 web.config,如果是 web.config,或者如果是 windows,则为 app.config)以:
<?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
元素。
在 section
元素的 name
属性中,确保替换 YourProjectName
使用您的实际项目名称。
我碰巧在一个类库项目中创建了一个 web 服务,然后我将配置文件(为了带来端点配置)复制(覆盖)到我的 windows 应用程序中,我开始遇到同样的问题。我无意中删除了 configSections
。
关于c# - 配置系统初始化失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6436157/