구성 시스템을 초기화하지 못했습니다
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 인 경우 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
요소 여야합니다 .
요소 의 name
특성에서 실제 프로젝트 이름으로 section
바꾸 YourProjectName
십시오.
클래스 라이브러리 프로젝트에서 웹 서비스를 만든 다음 엔드 포인트 구성을 가져 오기 위해 구성 파일을 Windows 응용 프로그램에 복사 (덮어 쓰기)하고 동일한 문제가 발생하기 시작했습니다. 실수로 제거했습니다 configSections
.
그것은 나를 위해 일했다, 그것이 도움이되기를 바랍니다
c : \ Users \ username \ AppData \ Local \ appname 및 c : \ Users \ username \ AppData \ Roaming \ appname 에서 이전 구성 파일을 삭제 한 다음 응용 프로그램을 다시 시작하십시오.
때때로 Windows에서
C : \ Users \ App Data \ Local \ "사용자 이름"...
이 폴더를 삭제하고 완료하십시오. 시도 해봐.
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.
I had this same problem with an MSTest class: Marlon Grech in his article says "the element has to be defined as the first element in the App.config."
So make sure that is the first element in under the element. I had put AppSettings first.
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!
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.
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.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="xyz" value="123" />
</appSettings>
</configuration>
Wow it took me forever to figure out this one. For some reason changing the attribute [assembly: AssemblyCompany("CompanyName")]
at AssemblyInfo.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!
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
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.
In my case the only solution was to add the reference to the System.Configuration
in my Test project as well.
This is kinda dumb, but for me I fixed it by doing a get latest from source control on my code. I think there was some new configuration element that was added by someone else, and I needed to overwrite my configuration files. OP shows the error I had gotten, which wasn't really pointing me in the right direction.
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 are dealing with an Azure WebJob - I had to remove the following after upgrading to the latest 4.6.1.
<compilation debug="true" targetFramework="4.6.1">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
Hope this helps.
In my case, within my .edmx file I had run the 'Update Model From Database' command. This command added an unnecessary connection string to my app.config file. I deleted that connection string and all was good again.
I solved the problem by using the below code
<?xml version="1.0" encoding="utf-8" ?>
<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>
<appSettings>
<add key="SPUserName" value="TestUser" />
<add key="SPPassword" value="UserPWD" />
</appSettings>
</configuration>
Try to save the .config file as utf-8 if you have some "special" characters in there. That was the issue in my case of a console application.
As @Flash Gordon mentioned in his comment, you will need to define any custom tag (as a section) in your App.config file, under <configSections>
. For example, you're working on a test automation project with SpecFlow & adding <specFlow>
tag, then a simplest version of App.config will look like this:
I just had this and it was because I had a <configuration>
element nested inside of a <configuration>
element.
After a long search I realised, this exception has an inner exception that tells you exactly what is wrong with your config file
참고URL : https://stackoverflow.com/questions/6436157/configuration-system-failed-to-initialize
'IT story' 카테고리의 다른 글
Jade / Pug로 인라인 JavaScript를 어떻게 렌더링 할 수 있습니까? (0) | 2020.04.29 |
---|---|
플라스크에 선택적 URL 매개 변수가 있습니까? (0) | 2020.04.29 |
2 행에서 파일을 읽거나 헤더 행을 건너 뜁니다. (0) | 2020.04.29 |
유형별로 WPF 창에서 모든 컨트롤 찾기 (0) | 2020.04.29 |
SQL Server Management Studio, 실행 시간을 밀리 초로 줄이는 방법 (0) | 2020.04.29 |