我在我的项目中使用了许多事务:像这样:
bool retVal = true;
string errorCode = string.Empty;
try
{
result = RecordsDal.ReadAllDoneRecords();
retVal = Export(result, out errorCode);
}
catch
{
Errorlog(errorCode, ex.Message);
MessageBox.Show("Error Export "+ Environment.NewLine + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false;
}
出口:
public static bool Export(List<Record> result, out string error)
{
bool retVal = true;
error = "sqlCeConnection";
SqlCeConnection sqlCeConnection = null;
error = "Initializiong";
SqlTransaction trans = null;
try
{
error = "Begin";
.......
error = "End";
}
catch (Exception ex)
{
trans.Rollback();
retVal = false;
}
}
我使用错误日志来了解我的问题所在,
该应用程序在许多客户端中都可以正常工作,但是我在新客户端中安装了该应用程序,并且文件日志出现错误,出现代码错误和异常 ex.Message
初始化:对象引用未设置为对象的实例
这一行的错误:SqlTransaction trans = null;
抱歉,我找到了真正的问题,没有安装 sqlCe,并且有 ex.innerexception = null 日志保存了这个错误而不是真正的错误