1

我有一个使用类型化数据集表适配器查询 SqlCe 数据库的 WinForm 应用程序。我有一个主窗体程序集和一个处理每个数据库操作的数据库程序集。我在事务中使用 tableadapter 更新时遇到问题,如果有人能给我任何想法,我将不胜感激。

Update() 方法给出了这个错误:

"The connection object can not be enlisted in transaction scope."

这是我的代码:

namespace Main
{
    public class MainForm
    {
        private MyDbAssembly.MyDbClass db;

        //instantiate and db fill methods omitted..

        private void DeleteStuff()
        {
            using (TransactionScope trans = new TransactionScope())
            {
                this.db.Delete(id);
                UpdateDb();

                trans.Complete();
            }
        }

        private void UpdateDb()
        {
            //bindingsource endedit & datagridview endedit methods omitted..
            this.db.Update();
        }
    }
}

namespace MyDbAssembly
{
    public class MyDbClass
    {
        private myTypedDataset myDataSet;
        private myTypedDataSetTableAdapter.MyTable1Adapter table1Adapter;

        //instantiate methods omitted..

        public void Delete(Guid id)
        {
            this.myDataSet.MyTable1.FindByID(id).Delete();  
        }

        public void Update()
        {
            this.table1Adapter.Update(myDataSet.MyTable); //<-- ERROR LINE
        }
    }
}
4

1 回答 1

1

因为您在 TransactionScope 跨范围之外创建了 table1Adapter。

于 2010-02-11T11:34:06.987 回答