SQL Server CE rollback does not undo delete.

Posted by INTPnerd on Stack Overflow See other posts from Stack Overflow or by INTPnerd
Published on 2009-10-26T19:18:16Z Indexed on 2010/05/18 3:20 UTC
Read the original article Hit count: 227

I am using SQL Server CE 3.5 and C# with the .NET Compact Framework 3.5. In my code I am inserting a row, then starting a transaction, then deleting that row from a table, and then doing a rollback on that transaction. But this does not undo 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 indicate that everything works as expected until the very end where the table has a count of 0 indicating the rollback did not undo the deletion.

© Stack Overflow or respective owner

Related posts about sql-server-ce

Related posts about c#