Solved

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

Posted on 2006-06-15
5
16,302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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