SQL Server CE rollback does not undo uninstall

I am using SQL Server CE 3.5 and C # with .NET Compact Framework 3.5. In my code, I insert a row, then start a transaction, then delete that row from the table, and then roll back that transaction. But that doesn't override the deletion. Why not? Here is my code:

SqlCeConnection conn = ConnectionSingleton.Instance;
conn.Open();
UsersTable table = new UsersTable();
table.DeleteAll();
MessageBox.Show("user count in beginning after delete: " + table.CountAll());
table.Insert(
new User(){Id = 0, IsManager = true, Pwd = "1234", Username = "Me"});
MessageBox.Show("user count after insert: " + table.CountAll());
SqlCeTransaction transaction = conn.BeginTransaction();
table.DeleteAll();
transaction.Rollback();
transaction.Dispose();
MessageBox.Show("user count after rollback delete all: " + table.CountAll());

      

The messages show that everything is working as expected until the very end, where the table has a count of 0, indicating that the rollback does not undo the delete.

+2


source to share


1 answer


I just got a response on the Microsoft forum. You need to associate the SqlCeComand object with a transaction using the transaction property of the SqlCeCommand object.



+6


source







All Articles