locked
SqlConnection error RRS feed

  • Question

  • I am getting the following on error:

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

    on the following line of code which works in VS2003.

    Dim oSQLConn As SqlConnection = New SqlConnection("Server=cin-sql03;Database=axMCO;User ID=userid;Password=password;Trusted_Connection=False")

    Any help or suggestions would be greatly appreciated.

    Thanks!

    Wednesday, August 10, 2005 11:05 AM

Answers

  • Ahah, now that provides more information.

    It appears that your configuration file has an unrecognized element in it called AppSettings.

    XML files (and hence configuration files) are case-sensitive. Try changing the element's name from <AppSettings></AppSetings> to <appSettings></appSettings>.
    Wednesday, August 10, 2005 11:52 AM

All replies

  • Can you post the result of calling ToString() on the exception being thrown?

    For example:


    Try

       Dim oSQLConn As SqlConnection = New SqlConnection("Server=cin-sql03;Database=axMCO;User ID=userid;Password=password;Trusted_Connection=False")

    Catch ex as Exception

       MessageBox.Show(ex.ToString())

    End Try

     

    Wednesday, August 10, 2005 11:26 AM
  • David,

    Thanks for responding here's the results:

    A first chance exception of type 'System.TypeInitializationException' occurred in NewAXIndexApp.EXE

    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.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section AppSettings. (C:\NewAXIndexAppv2\bin\NewAXIndexApp.EXE.config line 3)

    at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()

    at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)

    --- End of inner exception stack trace ---

    at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)

    at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)

    at System.Configuration.ConfigurationManager.GetSection(String sectionName)

    at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()

    at System.Diagnostics.DiagnosticsConfiguration.Initialize()

    at System.Diagnostics.DiagnosticsConfiguration.get_PerfomanceCountersFileMappingSize()

    at System.Diagnostics.SharedPerformanceCounter.GetCategoryData()

    at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName, PerformanceCounterInstanceLifetime lifetime)

    at System.Diagnostics.PerformanceCounter.Initialize()

    at System.Diagnostics.PerformanceCounter.set_RawValue(Int64 value)

    at System.Data.ProviderBase.DbConnectionPoolCounters.Counter..ctor(String categoryName, String instanceName, String counterName, PerformanceCounterType counterType)

    at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)

    at System.Data.SqlClient.SqlPerformanceCounters..ctor()

    at System.Data.SqlClient.SqlPerformanceCounters..ctor()

    at System.Data.SqlClient.SqlPerformanceCounters..cctor()

    --- End of inner exception stack trace ---

    at System.Data.SqlClient.SqlConnectionFactory..ctor()

    at System.Data.SqlClient.SqlConnectionFactory..cctor()

    --- End of inner exception stack trace ---

    at System.Data.SqlClient.SqlConnection..cctor()

    --- End of inner exception stack trace ---

    at System.Data.SqlClient.SqlConnection..ctor(String connectionString)

    at NewAXIndexApp.Login.Button4_Click(Object sender, EventArgs e) in C:\NewAXIndexAppv2\Login.vb:line 64

    at System.Data.SqlClient.SqlConnection.Dispose(Boolean disposing)

    at System.ComponentModel.Component.Finalize()

    Wednesday, August 10, 2005 11:39 AM
  • Ahah, now that provides more information.

    It appears that your configuration file has an unrecognized element in it called AppSettings.

    XML files (and hence configuration files) are case-sensitive. Try changing the element's name from <AppSettings></AppSetings> to <appSettings></appSettings>.
    Wednesday, August 10, 2005 11:52 AM
  • That worked!!!  Unbelievable...  Thanks so much David.  I don't believe I would have caught that anytime soon.   Your help is greatly appreciated!!!

    John

    Wednesday, August 10, 2005 12:11 PM
  • David,

    Can this be filed as a bug? The top level exception should explain what the actual problem is.

    Regards,

    Justin Dearing
    Monday, May 21, 2007 2:22 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, P

     

    I see the comment about Windows 2000 or later, but I'm running XP.

     

    Anyone have any thoughts on this?

    Wednesday, May 14, 2008 12:15 PM