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.
Wow it took me forever to figure out this one. For some reason changing the attribute
[assembly: AssemblyCompany("CompanyName")]
atAssemblyInfo.cs
made this error disappear. I was referencing a project that had a different value for the attribute[assembly: AssemblyCompany("CompanyName")]
. I maked sure both projects had the same attribute value and it worked great!If you've added your own custom configuration sections to your
App.Config
, make sure you have defined the section in the<configSections>
element. I added the my config XML but forgot to declare the configuration section up top - which caused the exception "Configuration system failed to initialize" for me.In my case the only solution was to add the reference to the
System.Configuration
in my Test project as well.I too faced the same problem, But accidentally i written the without writting the ,the previous one should go inside this tags. thus the 'Configuration System Failed to Initialize' error was arising. Hope it will help
In My case, I have two configsections in the app.config file. After deleting the one hiding in the code lines, the app works fine.
So for someone has the same issue, check if you have duplicate configsections first.
If you have User scoped settings you may also have a user.config file somewhere in the [Userfolder]\AppData\Local[ProjectName] folder.
If you later remove the User scoped settings the user.config will not automatically be removed, and it's presence may cause the same error message. Deleting the folder did the trick for me.