DucDigital DucDigital - 1 year ago 127
C# Question

Exception: type initializer for 'system.data.sqlclient.sqlconnection'?

I couldn't figure out what is the problem for this exception.

The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception

First attempt: I was using the WCF Service to make some small application. It works just fine and I can use the LINQ properly. After 2 or 3 days. Maybe after I close Visual studio and load the project again. The exception appear.

The 2nd attempt also the same. I create another project and it work just fine until I do something else (I do not change any code)

SQL Server working fine and I can connect through SQL Management Studio without problem.

A click at Debug error lead me to the connection string from linq file.

What could be the problem? I tried to search but couldn't find the answer to resolve this.

Thank you

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download