The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
-
Tuesday, June 07, 2005 6:58 AMTest 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
-
Wednesday, October 05, 2005 8:56 PMThis 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?
-
Wednesday, June 13, 2007 7:00 AM
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.
-
Thursday, August 02, 2007 8:29 PM
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.
-
Tuesday, October 09, 2007 6:42 AMHi,
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.. -
Wednesday, October 10, 2007 6:12 AM
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 !!!
-
Wednesday, October 10, 2007 9:39 AMI change config file but ttill getting same error.
-
Monday, October 15, 2007 5:50 AMNo help?
-
Wednesday, May 14, 2008 12:10 PM
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?
-
Sunday, May 25, 2008 11:33 AM
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...
-
Friday, January 09, 2009 8:12 PMI 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; -
Thursday, January 15, 2009 5:36 PM
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. -
Wednesday, August 26, 2009 9:04 AM
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 by cup_of_tea Thursday, August 27, 2009 9:45 AM
-
Tuesday, September 15, 2009 8:40 AMCheck 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.
-
Thursday, November 05, 2009 6:47 AMHey I faced similar problem but moving the <ConfigSections> Node moved after <Configuration> node resolves the issue.
-
Friday, November 13, 2009 11:54 PMI faced this problem and tried all the abovebutno solutionare there anyone help me???????thanks
-
Saturday, November 14, 2009 3:16 PM
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 !!! :) -
Saturday, November 14, 2009 9:41 PMokthanks 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
-
Sunday, November 15, 2009 7:55 PMIt 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. -
Tuesday, November 24, 2009 1:25 AMIf 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;
-
Tuesday, May 18, 2010 1:44 PM
Same problem, same message "This operation is only supported on Windows 2000 SP3 or later operating systems." on a windows 2003 R2 sp2...
My solution is....
Check the property of the executable, Compatibility panel, and see if the compatibility is set for Windows 2000... this was the solution of my problem.
Bye,
Matteo Conta
-
Tuesday, July 20, 2010 11:25 AM
Hello, This maybe a little late in the day but had same problem with my ap.config. Im running a vb 2005 app on xp. The app.config file references a runtime command as the first command within the configuration section. This gave me the error. I moved the runtime command to the end of the configuration section (ie. after any connection statement, etc) and it worked ok. The error disappeared.
Hope this help.