问题的描述:单步运行没有问题,但是正常运行就出下面的错误“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] <%X{auth}> - %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] <%X{auth}> - %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编写