The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
- Test it on a virtual PC running SQL 2000 on a Win 2003 PKLATFORM.
Throws the above error on win 2000 machine with a networked SQL 2000 server
Is this an AD thing???
All Replies
- This could be due to missing references. Or it could be due to an error in the app config file. Is it possible for you to post your code?
hey it may be the problem with app.config settings.
u hv to code like this
<
appSettings><
add key ="ConnectionString" value="Data Source=server name;Initial Catalog=db name;User ID= sa;Password= sa"/></
appSettings>if u code this wrongly ,typeintializer error w'll throw.
Also if the key name is used different from app.config also exception will throw.
Yes, check your settings to see if you have one that is a connection string that is conflicting with the one you have. I had the same problem and that fixed it.
- Hi,
I got the same error. I use windows authentication. And i have several web.config files on each sub folder to authenticate users by their groups. And my web.config file on this folder is just like this:
And i can run several dts and sp with same (Microsoft) sqlhelper.cs class. But this gives me the error.Code Block<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
</system.web>
</configuration>
How can i solve this?
Regards.. OK, This is very shocked me! when i reopen my project and run it, I face this Exception but in fact the Config File (exp : app.config) contains this wrong Information and when I correct it the problom solved!
-- Contains Key that is not set yet (Line No 3,4,5)
<?
xml version="1.0" encoding="utf-8" ?><configuration>
<appSettings>
<add key="" value="site"/>
</appSettings>
<configSections>
</configSections>
</configuration>
-- Correct One
<configuration>
<
configSections></
configSections></configuration>
Just this !!!
- I change config file but ttill getting same error.
- No help?
I'm getting the same error message but in a different scenario. I have a .NET DLL with COM interop that we call from a VB6 application. When I run the app from the VB6 IDE, everything works fine. But when I create an EXE and run from that, the exception is thrown on this line of code in the DLL:
SqlConnection
cn = new SqlConnection("Data Source=serverName;Initial Catalog=S2;uid=userID;pwd=password;");The exception.ToString() returns the following:
System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw an exception.
---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception.
---> System.PlatformNotSupportedException: This operation is only supported on Windows 2000 SP3 or later operating systems.
at System.Security.Principal.SecurityIdentifier..ctor(WellKnownSidType sidType, SecurityIdentifier domainSid)
at System.Diagnostics.SharedUtils.EnterMutexWithoutGlobal(String mutexName, Mutex& mutex)
at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName, String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime lifetime)
at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName, PAnyone have any thoughts on this?
Yeah this is one i run into here and there usually when i try be smart and create a connection as a property of a class..
move it into a method presto bye bye...
eg
class foo()
{
// dont make it a property.
Sql connection con = new con(conStr).. bla bla ( BAD dont over think stuff.. code like a lamo )
int bar(int i)
{
//***move it to here and test..
//so not a propety any more move it here..
SqlConnection con....
}
Un huh...
- I faced a similar problem when I was working with WCF, which is set to allow impersonation.
Two things i did solved my problem
1. On the wcf config file I corrected my connection string.
2. On the client side of app I set
ServiceClient..ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; If you are using VS 2008 with WCF (and especially with regard to integrated security usage) can I recommend the above from CSharpDev and if that doesn't work, use this as your perrenial fall back for fixing what appears to be a Visual Studio with WCF problem.
Open a VS 2008 Command Prompt and use this:
aspnet_regiis -i
And then:
"%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation/ServiceModelReg.exe" -i -x
And then:
iisreset
This should sort out your problems.
However I must admit that on one machine I use this is a problem and not on another (so far), so it may well be something in the PC's build.- I found replacing the machine.config file resolved the error. It can become corrupted. Lift it from a working machine.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config- Proposed As Answer bycup_of_tea Thursday, August 27, 2009 9:45 AM
- Check the COM component and .DLL is available in the installation folder wher .exe exists. make sure you are referencing COM component from your installation directory or from any other where with the correct path. Else you have to register the component. See more exception help http://dileepsol.blogspot.com.
- Hey I faced similar problem but moving the <ConfigSections> Node moved after <Configuration> node resolves the issue.
- I faced this problem and tried all the abovebutno solutionare there anyone help me???????thanks
I have faced this is a number of times. Sometimes it can be an installation of the .net framework that is at fault (usually 2.0). I have used the following tool to remove .net 2.0 and then reinstall from it from Microsoft.
http://blogs.msdn.com/astebner/pages/8904493.aspx
Worked for me twice !!! :)- okthanks for your care cup_of_teai found my problemmy problem is the application is not read the connection string in app.config so when i start with debugging, it is all write but when start without debugging the exception is thrownanother thingwhen i clear the comming from machine.config as the following code<configuration><clear/><connectionStrings><add name="ConnectionString"connectionString="Data Source=.;Initial Catalog='Computer Sales System';Integrated Security=True"/></connectionStrings></configuration>the exception is thrown in both sidessoi understand that the connection string in app.config is not read by applicationso i want to know why???????? and what is the solution for this problemthanks
- It sounds like there are multiple versions of the app.config file. When you build the application (in release) make sure the config file is copied to the output directory and that your application points to the correct file.
You can set the app.configs properties to 'always copy to output directory'. Also there may be a cached version of the file somewhere so I would search the web for how to clear caches etc. I think you can do 'Clean Solution' from build menu. Good luck. - If anyone sees this
Had this problem with a WPF application calling a web service using entity framework - on the same wcf server had an existing web service, also using entity framework which had no problems - wcf had all the attributes for impersonation
On the wcf rich client, added the following line right after i created the client and all was well
_catalogService
.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;


