Deleting a SQL CE database

R

Richard Kucia

I'm playing around with SQL CE for the first time, and it didn't take long
for me to come up with a puzzle. I created a little test app that gives the
user 3 buttons: Create, Insert and Display. "Create" deletes the SQL CE
database file (if it exists) and then creates a empty database with one
empty table named Books. "Insert" opens a connection to the DB, inserts 3
rows into the table "Books", and closes the connection. "Display" opens a
connection to the DB, populates a DataSet off a DataAdapter, sets a grid's
DataSource to the DataSet's "Books" table, and closes the connection. No
mystery here -- all ordinary stuff.

If I perform the following sequence, I see 6 rows in the grid, not 3.

(a) Create (creates an empty database with one table "Books" and zero rows)
(b) Insert (inserts 3 rows into "Books")
(c) Display (shows 3 rows)
(d) Create (same as (a) above)
(e) Insert
(f) Display <-- shows 6 rows, not 3

I have confirmed with File Explorer that the database file is deleted and
then recreated as part of the Create logic.

As a second test, I tried deleting the database between steps (e) and (f);
SQL CE was smart enough to throw an exception when I tried the "Display"
button. So it looks like SQL CE requires the DB file to exist, but its
contents are cached, and there's no date/time stamp checking to detect the
above condition.

Obviously there's some caching going on here. Exactly how does it work?

Richard Kucia
 
R

Richard Kucia

That's exactly the problem. I didn't realize that DataAdapter.Fill()
*appended* rows if the target DataSet already had the target table with some
rows in it. Thanks for pointing out my error.

Richard Kucia

Dan Ardelean said:
The cache might be on your DataSet. Do you also destroy the DataSet
object?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top