Reputation: 121
i have a problem in inserting some data into a table.
I have done a program with a simple DB. I use
Some quotes
Open the connection :
SqlCeConnection conn = new SqlCeConnection("DataSource = " + file);
conn.Open();
Write a row :
String sql = "INSERT INTO Mercati(id,descr) VALUES(643,'SHAMPOO')"
SqlCeCommand execute = conn.CreateCommand();
execute.CommandText = sql;
int result = execute.ExecuteNonQuery();
execute.Dispose();
The data table is like that :
CREATE TABLE Mercati(id int PRIMARY KEY,descr nvarchar(40));
This is inside a try / catch. And every time result is 1 ( i cutted away debugging code ). I repeat that on different tables, with different data.
But SOMETIMES (1 time avery 4/5 transmissions) with one table the data are not inserted, with result=1 and no exceptions.
I'm really out of ideas. I cant understand what's the problem. Or simply how can i resolve that issue. Any solution or advise ?
Thanks a lot Daniele
Upvotes: 1
Views: 1483
Reputation: 121
I have resolved.
After INSERTs i do some backups, then i reset the device. BUT i didn't close the DB.
The strange is that i did the advice of SeaDrive, and after my insertions the table contains the exact number of rows. I did 9 INSERT and my select return 9 Rows.After reset i have only 1 row.
I think there is some sort of cache, that is transparent during execution, but leave the fisical file unchanged, unless the DB it's closed.
I hope that will help other poor developper like me to close their DB :D
Upvotes: 0
Reputation: 4292
The only thing I can think of that would make inserted data disappear is transaction control. Do you have any COMMIT/ROLLBACK programming?
Is there any chance that the connection string gets changed to a different DB?
As a debugging strategy, my first approach would be to read data from table after the insert to be sure the data is there. Look at the specific row and the total number of rows. I might try to read it at different points in the program to see when the row disappears.
Upvotes: 2