Configuration System Failed to Initialize

2019-01-03 02:26发布

I'm new to Visual Studio. I'm currently creating a Login form.

I have this code.

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?

Please help.

19条回答
叛逆
2楼-- · 2019-01-03 03:24

Same problem with me I solved my problem by removing verion="v3.5" from App.config.

Before

 <?xml version="1.0" encoding="utf-8"?>
  <configuration>

  <startup>

 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
 </startup>
 <supportedRuntime version="v3.5" />//Remove this
</configuration>

Solution

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <startup>

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
  </startup>
  </configuration>

Here is how to use version on

MSDN Support Runtime Element

查看更多
登录 后发表回答