none
need help on Exception "The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception"

    Question

  • Hi,

     

    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 "

    + " WHERE id = object_id('" + tablename + "') order by colid";

    OleDbConnection conn = new OleDbConnection(connString);

    OleDbCommand comm = conn.CreateCommand();

    comm.CommandText = sql;

    comm.CommandType = CommandType.Text;

     

    try

    {

    conn.Open(); // exception here

     

     

    Thanks,

     

    Maggie

     

    Wednesday, September 24, 2008 11:56 PM

All replies

  • 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

     

    Val Mazur

    http://www.xporttools.net

    Thursday, September 25, 2008 9:58 AM
    Moderator
  • 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 System.Transations.Transaction.get_Current()

    at System.Data.Common.ADP.IsSysTxEqualSysEsTransaction()

    at System.Data.Common.ADP.NeedManualEnlistment()

    at System.Data.OleDb.OleDbConnection.Open()

    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)

    at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()

    at System.Diagnostics.DiagnosticsConfiguration.Initialize()

    at System.Diagnostics.DiagnosticsConfiguration.get_Sources()

    at System.Diagnostics.TraceSource.Initialize()

    at System.Diagnostics.TraceSource.get_Switch()

    at System.Transactions.Diagnostics.DiagnosticTrace..cctor()

     

    Thanks
    Thursday, September 25, 2008 2:56 PM
  • Ok, the exception gone when I added an empty app.config file. I totally don't understand on this.

     

    Any one has clue why it needs an app.config to initialize Access DB connection?
    Thursday, September 25, 2008 3:31 PM
  • Are you using SQL Server or Access DB? If it is an Access, your connection string will not work, since it is for SQL Server
    • Proposed as answer by $andman Thursday, May 28, 2009 2:31 PM
    Friday, September 26, 2008 9:54 AM
    Moderator
  • The problem at least for me was a typo in my app.config (I had a custom scetion I forgot to define) Why OLEDb triggers this I do not know

    Thursday, May 28, 2009 2:32 PM
  • 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)
    Tuesday, February 01, 2011 5:09 AM
  • Gente el codigo está perfecto, no toquen nada del sistema. Lo unico que hay que hacer es desintalar los framework y volver a instalarlos, con eso funciona!!!!

    Wednesday, July 06, 2011 1:24 AM
  • I solved it by removing an empty section (configSections) in app.config

    After that i didn't receive the error.

    Wednesday, August 31, 2011 12:01 PM
  • I've only rename app.config file and rebuild project - that helps ! But when I compare config files - cannot find difference.Thanks!
    Thursday, August 16, 2012 3:34 PM