Link to home
Start Free TrialLog in
Avatar of lee_ingram
lee_ingram

asked on

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

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)
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

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.
Avatar of lee_ingram
lee_ingram

ASKER

The connection string works fine.  Im not using any .config files within my application.
ASKER CERTIFIED SOLUTION
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.