need help on Exception "The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception"
I have a function to obtain column properties of a table in ole database. Strange thing is that the program ran successfully within VS2008, but after I built and run it in windows, it gives me exception "The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception". I looked for this exception in internet, and they suggest delete app.config and rebuilt application, but I didn't create a app.config for this program. So I lost..
Can anyone help? Following is my code.Code Snippet
string connString = @"Provider=SQLOLEDB;Data Source=xxxx;Initial Catalog=HelpExchange;User Id=xxxx;Password=xxxx";
string tablename = "HD_RequestTable"; // this.listBox1.SelectedValue.ToString();string sql = "SELECT name, type_name(xtype), length FROM syscolumns "
comm.CommandText = sql;
What is inside of stack trace of your exception. Quite possible you do not have permissions to access system tables and you get security exception. On other side, if you are using system tables I would assume you are working with SQL Server. In this case it is better to use native SQL Server provider (System.Data.SqlClient namesapce) and get information about objects using GetSchema method of SqlConnection
- Edited by VMazurModerator Wednesday, July 06, 2011 10:32 AM
I don't think it is permission problem because it connected to the database successfully if I ran it in Visual Studio 2008.
Here is the stack trace
The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.
at EDSHelpWatch.frmAddCriterion.GetTableColumnList() in C:\....frmAddCriterion.cs: line 48
Inner Exception: Configuration system failed to initialize
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigruationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.configuration.Internal.IlnternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configruation.PrivilegedConfigurationmanager.GetSection(String sectionName)
I got the same exception when I packaged a installer file and install it on another computer. I have checkd my project and confirm I didn't use app.config. What was the problem? After remove all visions of the DotNet Framework and reinstall again from network. The exception was never thrown again! What's wrong with DotNet Framwork?(Vision 2.0 SP2)