C# 中“System.Transactions.Diagnostics.DiagnosticTrace”的类型初始值设定项引发异常。Access连接异常,解决方案

问题的描述:单步运行没有问题,但是正常运行就出下面的错误“System.Transactions.Diagnostics.DiagnosticTrace”的类型初始值设定项引发异常。代码如下:

 

        //构造函数

        public AccessOP(String MDBFileName, String Password)

        {

 

            String Str = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet Oledb:Database Password={1}", MDBFileName, Password);

            Conn = new OleDbConnection(Str);  //连接数据库

            Conn.Open();

        }

在执行Conn.Open();时,会弹出上述问题,

 解决办法:问题出在app.config,原始

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

   <!-- This section contains the log4net configuration settings -->

  <log4net>

    <!-- Define some output appenders -->

    <appender name="LogFileAppender" type="log4net.Appender.FileAppender">

      <param name="File" value="log-file.txt" />

      <!-- Example using environment variables in params -->

      <!-- <param name="File" value="${TMP}//log-file.txt" /> -->

      <param name="AppendToFile" value="true" />

      <!-- An alternate output encoding can be specified -->

      <!-- <param name="Encoding" value="unicodeFFFE" /> -->

      <layout type="log4net.Layout.PatternLayout">

        <param name="Header" value="[Header]/r/n" />

        <param name="Footer" value="[Footer]/r/n" />

        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />

      </layout>

      <!-- Alternate layout using XML  

   <layout type="log4net.Layout.XMLLayout" /> -->

    </appender>

 

    <!-- Setup the root category, add the appenders and set the default level -->

    <root>

      <level value="ALL" />

      <appender-ref ref="LogFileAppender" />

      <!-- <appender-ref ref="A" /> -->

    </root>

 

    <!-- Specify the level for some specific categories -->

    <logger name="SLog4net.Form1">

      <!-- <appender-ref ref="B" /> -->

      <level value="ALL" />

      <appender-ref ref="RollingLogFileAppender" />

    </logger>

  </log4net>

 

</configuration>

 

修改后:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <configSections>

    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version= 2.0.0 .0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

      <section name="ConvertData.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version= 2.0.0 .0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />

    </sectionGroup>

    <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />

  </configSections> 

  <!-- This section contains the log4net configuration settings -->

  <log4net>

    <!-- Define some output appenders -->

    <appender name="LogFileAppender" type="log4net.Appender.FileAppender">

      <param name="File" value="log-file.txt" />

      <!-- Example using environment variables in params -->

      <!-- <param name="File" value="${TMP}//log-file.txt" /> -->

      <param name="AppendToFile" value="true" />

      <!-- An alternate output encoding can be specified -->

      <!-- <param name="Encoding" value="unicodeFFFE" /> -->

      <layout type="log4net.Layout.PatternLayout">

        <param name="Header" value="[Header]/r/n" />

        <param name="Footer" value="[Footer]/r/n" />

        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />

      </layout>

      <!-- Alternate layout using XML  

   <layout type="log4net.Layout.XMLLayout" /> -->

    </appender>

 

    <!-- Setup the root category, add the appenders and set the default level -->

    <root>

      <level value="ALL" />

      <appender-ref ref="LogFileAppender" />

      <!-- <appender-ref ref="A" /> -->

    </root>

 

    <!-- Specify the level for some specific categories -->

    <logger name="SLog4net.Form1">

      <!-- <appender-ref ref="B" /> -->

      <level value="ALL" />

      <appender-ref ref="RollingLogFileAppender" />

    </logger>

  </log4net>

 

</configuration>

 

加入<configSections>段,问题就解决了,目前为啥是这样,我还不清楚,希望高手指点.

//Email:Landgis@126.com,yanleigis@21cn.com 2007.12.03编写

 

 
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值