c# - 配置系统初始化失败

标签 c# mysql visual-studio-2010 visual-studio authentication

我是 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/

相关文章:

c# - 将焦点设置到文本框中的按钮?

c# - 如何为响应式扩展制作自定义扩展

c# - Specflow - 带有数据表的场景轮廓

java - Java 中的 SQL 查询 : (JDBC) How to use the SELECT statement?

mysql - 查找数据库中丢失的数据

mysql - SQL 结果长度且搜索时不显示任何内容

c# - VS 2010 Beta 1 无法识别 System.Printing.PrintTicket 类

c# - 为什么会生成警告 CS1607 "The version specified for the ' product version' is not in the normal 'major.minor.build.revision' format?

visual-studio-2010 - VS 2010 : Where are solution settings stored?

c# - 具有多态对象数组的 JSON 反序列化