我有以下方法:
public void SaveReferenceUpdates(ReferenceUpdatesDataContract updates)
{
mTransaction = Connection.BeginTransaction();
try
{
// Do all the updates to get the database inline with the contract.
updates.UpdateFromContract();
// Do all the deletes to get the database inline with the contract.
updates.DeletesFromContract();
try{mTransaction.Commit();}
catch{throw;}
mTransaction = null;
}
catch (Exception e)
{
mTransaction.Rollback();
mTransaction = null;
throw;
}
}
(我已经取出了我所有的日志语句并折叠了一些方法以使其更具可读性。)
奇怪的是,有时(非常随机地)mTransaction
在提交步骤时为空。(由于这种情况发生得如此随机,所以当它从连接中获取事务时,我无法查看它是否为空。)
这个方法在两个地方被调用。一种是用户登录我的应用程序时,另一种是用户一段时间不活动时(基于关闭用户输入的计时器)。
我对什么可能导致SqlCeTransaction
( mTransaction
) 永远为空感到困惑。(帮助没有说明 BeginTransaction 返回的任何内容null
。)