Solved

The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception. vb.net gina SQL

Posted on 2006-06-15
5
16,089 Views
Last Modified: 2012-05-05
Hi,

I have written my own custom gina, which then calls into a .net assembly(dll).

Within this assembly im trying to connect to a SQL database, but receive the following error:

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

It happens on the following line in my code:

 _sqlCnn = New SqlConnection(connectionString)

where connectionString is a valid connection string as i use the same one as a previous application that worked.  Any idea? please note that im NOT logged in, so I believe the process is running under a SYSTEM account, the same as the windows logon app.

Full trace details are:

2006-06-15 13:46:05 ERR -1        ForgotPasswordService 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.ArgumentException: Illegal characters in path.
                                           at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
                                           at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
                                           at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
                                           at System.IO.Path.GetFullPath(String path)
                                           at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
                                           at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
                                           at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
                                           at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
                                           at System.Configuration.ClientConfigurationSystem..ctor()
                                           at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
                                           --- End of inner exception stack trace ---
                                           at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
                                           at System.Configuration.ConfigurationManager.GetSection(String sectionName)
                                           at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
                                           at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
                                           at System.Diagnostics.DiagnosticsConfiguration.Initialize()
                                           at System.Diagnostics.Switch.InitializeConfigSettings()
                                           at System.Diagnostics.Switch.InitializeWithStatus()
                                           at System.Diagnostics.Switch.get_SwitchSetting()
                                           at System.Diagnostics.TraceSwitch.get_Level()
                                           at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
                                           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()
                                           at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
                                           at CustomIE.DatabaseLibrary.StoredProcedure..ctor(String spName, String connectionString)
0
Comment
Question by:lee_ingram
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 16912352
You should be VERY sure of that connection string....use a debugger, and dump it out BEFORE it is used in the constructor.

It is probable, however, that there is an error in one of your .config files, since the system seems to be finding an illegal character within the System.Configuration tree.
0
 
LVL 1

Author Comment

by:lee_ingram
ID: 16918261
The connection string works fine.  Im not using any .config files within my application.
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 16919473
0
 
LVL 1

Author Comment

by:lee_ingram
ID: 16920031
Hi,

I saw this article easier, and decide to write a C++ Database access class.

Thanks for looking for me and helping out.

Cheers

Lee
0
 
LVL 1

Expert Comment

by:fagdata
ID: 21002278
This problem also occurs if the app.config file has been corrupted. For instance if you manually edited it, and there exists invalid section references.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now