I have a Windows Form application in VS 2013 and I'm trying to establish a database connection. Every time I run the program, however, I receive the following error:
An unhandled exception of 'System.Configuration.ConfigurationErrorsException' occurred in
System.Configuration.dll
Additional information: Configuration system failed to initialize
Here's what my files look like:
Program.cs
using System;
using System.Collections;
....
namespace ProgramName
{
static class FakeNameB
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs
using System;
....
namespace ProgramName
{
public partial class Form1 : Form
{
public Form1()
{
string CS = System.Configuration.ConfigurationManager.ConnectionStrings[<nameInApp.config>].ConnectionString.ToString();
InitializeComponent();
}
}
}
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ProgramName.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<configurationStrings>
<add name = <name> connectionString = "Data Source=<dataSource>;Initial Catalog=<catalog>;Integrated Security=True;" providerName="System.Data.SqlClient"></add>
</configurationStrings>
</configuration>
None of the suggestions in this post seemed to help, and I was not able to reference System.Configuration.dll like this post suggested. Any ideas?