I couldn\'t figure out what is the problem for this exception.
The type initializer for \'System.Data.SqlClient.SqlConnection\' threw an exception
I also faced that exception once when I reopened my project. In my case the Config file had empty tag and key as you can see below. I removed the appSettings tag to fix the problem.
< ?xml version="1.0" encoding="utf-8" ?>
< configuration>
< appSettings>
< add key="" value="site"/>
< /appSettings>
< configSections>
< /configSections>
< /configuration>
I have the same error. And I findout the solution for it by change "app.config":
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="O4E.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<applicationSettings>
<O4E.Settings>
<setting name="abc" serializeAs="String">
<value>xyz</value>
</setting>
</O4E.Settings>
</applicationSettings>
<appSettings>
<add key="" value=""/>
<add key="" value=""/>
</appSettings>
</configuration>
Note: Line [supportedRuntime version="v2.0.50727"] is the most importance.
A similar solution to those mentioned above, but in my case it was the applicationSettings tag within the app.config that needed to be removed.
Check if you have the following Windows hotfix installed - KB2840628 - for the .NET FW 4.0 (use Windows Control Panel->Programs+Features and click 'view installed updates') and if so try uninstalling it...
https://connect.microsoft.com/VisualStudio/feedback/details/793500/sqlclr-typeinitializationexception-in-sqlconnection-since-kb2840628
It resolved the problem for me.
sorry for the late response on this, but after investigating this issue for almost 3 days in a row I thought I'd share my results.
I had the same error pop up in SQL Server Reporting Services, more specifically the web portal after getting HTTP 503 Service Unavailable
errors on my browsers.
Turns out that the issue was related to both, the service account that runs the SSRS instance plus the account that connects to the database, which in my case was located on another server than the reporting instance. I haven't yet been able to pinpoint exactly where the problem lies inside the configuration and/or user rights, i.e. where do the accounts exactly need elevated rights. All in all seems that the underlying problem was that the account I was running the web portal code under, didn't have enough rights to call on the System.Data.SQLClient type.
TL;DR: Check your users permissions! Hope this helps someone, I had a long 3 days trying to figure this out.
This most likely means that there is an error in your app.config file, e.g. badly formed XML or unexpected elements. The error happens because the static fields inside SqlConnection read from app.config to determine trace detail level as described here: http://msdn.microsoft.com/en-us/library/ms254503.aspx