Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am developing a C# application with a .sdf database, I have SELECTs, UPDATEs and INSERTs, and all they work while I'm compiling the application.

I mean, I add, delete and modify records, and it works okay i can play with all my information while the app is running. BUT if I close the app and after it, I run it again, all the data is like in the begining, there's not any change in my DB.sdf

It looks like if all my changes were on the RAM memory or something like that...

This is my UPDATE code:


SqlCeConnection connDisp = new SqlCeConnection();
                    connDisp.ConnectionString = ("Data Source =" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\\ACB.sdf;Password=acaf;Persist Security Info=False;");
                    try
                    {
                        connDisp.Open();
                        StringBuilder query = new StringBuilder();
                        SqlCeCommand comm = new SqlCeCommand();
                        
                        query.Append("UPDATE ACCT SET NPL ='0004',MODO='M' WHERE NUVO='00003' AND NUIA= '01' AND NUPO= '00700' AND SMCT='000' ");
                        comm.CommandText = Convert.ToString(query);
                        
                        comm.Connection = connDisp;
                        comm.ExecuteNonQuery();
                        comm.Dispose();
                        this.Refresh();
                        connDisp.Close();
                    }
                    catch (SqlCeException exce)
                    {
                        MessageBox.Show("Exception: "+exce.Message);
                    }



**Any idea about Why I can't write on my .sdf database?**
I've visited lots of blogs but anyone helped me.
Is it wrong if I ask for a demo mobile app?

Hope somebody help me
Thank You..
Posted
Comments
CHill60 5-Feb-14 18:52pm    
Not sure about this ... have you got multiple copies of the database ... have a look in your debug and release folders for example. Or if the database is in a "protected" folder (e.g. Program Files) then it will have been virtualised.
Ripoll_Ionn 5-Feb-14 19:05pm    
I have just 1 database, but as far as I know, when I compile my app, my database is copied to my bin\debug foler. Isn't it?

But I think it's not the problem because I made the app, and I installed it on my windows mobile.. -And my app is on C:\Users\Myuser\- and The problem continues...

Another idea?
TnTinMn 5-Feb-14 19:45pm    
When you created the datasource, did you click Yes when prompted by this dialog?
---------------------------
Microsoft Visual Studio
---------------------------
The connection you selected uses a local data file that is not in the current project. Would you like to copy the file to your project and modify the connection?
---------------------------
Yes No Help
---------------------------

This is a common issue when people say their changes when running under VS are not persisting. If you did, you will see the database file in the Solution Explorer. Check the properties of the file. Most likely "Copy To Output" is set to "Copy Always"; change it to "Copy If Newer".
Ripoll_Ionn 6-Feb-14 10:14am    
I saw it, It says "Copy if newer"... In Build action section, it says "content"...
TnTinMn 6-Feb-14 19:37pm    
"I mean, I add, delete and modify records, and it works okay i can play with all my information while the app is running. BUT if I close the app and after it, I run it again, all the data is like in the begining, there's not any change in my DB.sdf"
Does this mean that you have pulled the modified data and show the the modified table in the UI or does it just mean that nothing crashed?

1 solution

I finally understand what happened with this topic.

When I run my application, my database was selected from my root, but when It was compiled, my database was moved to \bin\bd.sdf

So, all my updates and deletes were done BUT ON MY bin\database.sdf.

I closed the applicatión and after I want to compile it again, the full \bin\db.sdf was replaced with my first one.

And this was like "cycled".


In conclusion: I just had to watch where the database was taken, and where the changes were made in it..

My codeline are OK.

Thank You guys!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900