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.
I started to get this problem after uninstalling Oracle Client Drivers and it removed my C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\machine.config!
Copying it from another computer resolved the problem.
I know this has already been answered but I had exactly the same problem in my unit tests. I was tearing my hair out - adding an appSettings section, and then declaring the configuration section as per the answer. Finally found out that I had already declared an appSettings section further up my config file. Both sections pointed to my external settings file "appSettings.config" but the first appSettings element using the attribute file whilst the other used the attribute configSource. I know the question was about the connectionStrings. Sure enough, this happens if the appSettings element is the connectionStrings element being duplicated with different attributes.
Hopefully, this can provide someone else with the solution before they go down the path I did which leads to wasting an hour or two. sigh oh the life of us developers. We waste more hours some days debugging than we spend developing!
If you are dealing with an Azure WebJob - I had to remove the following after upgrading to the latest 4.6.1.
Hope this helps.
It is worth noting that if you add things like connection strings into the app.config, that if you add items outside of the defined config sections, that it will not immediately complain, but when you try and access it, that you may then get the above errors.
Collapse all major sections and make sure there are no items outside the defined ones. Obvious, when you have actually spotted it.
Delete old configuration files from c:\Users\username\AppData\Local\appname and c:\Users\username\AppData\Roaming\appname and then try to restart your application.