Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have create a windows Forms application.
My application is using an entity framework model connected to a SQLExpress Database.
The database is has some information in before the start of the application.
When I start the application and use the existing information, everything is fine, but my application cant save, update anything to the database, and if enter some information and try to save it to the database, my application says it has saved.
When I close my application and restart it, the information I previously saved is not there, but the information that was existing before is still there.

Please help me, im not sure if there is a problem with my app.configs connection string to if I did something else wrong.

here is my connection string from my app.config just in case you need it.
<add name="NzhelelePartsCenterEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NzhelelePartsCenter.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

Here is a short Insert code snippet
financials = new NzhelelePartsCenterEntities();

tbl_Users user = new tbl_Users();
user.FirstName = txtFirstName.Text.ToString().Trim();
user.LastName = txtLastName.Text.ToString().Trim();
user.UserName = txtUsername.Text.ToString().Trim();
user.Password = txtPassword.Text.ToString().Trim();


MessageBox.Show("User has been inserted into the database successfully.", "User Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
Updated 27-Nov-13 5:20am
Dave Kreskowiak 27-Nov-13 11:15am    
Not neough information. Use the SQL Server Management Studio and open up your database and examine it to make sure the data was written. EF will usually throw and exception if it isn't able to write to the database.

You also haven't supplied any code snippets that are saving the changes to the database, so it's impossible to tell you what you're doing wrong.

Also, are you initializing the database with this data? Is your EF context setup to drop and create the database every time your app starts? Do you have this database file as part of your project? Is it being copied to the BIN folder every time you build your app, thereby possibly overwriting your running copy of the database?
D3m0n1CMoNkEy 27-Nov-13 11:22am    
I have updated my question with another example, and to answer your other questions... the EF doesn't drop and create the database every time the app starts, the database file that the EF is connected to is in the project folder, and I'm not sure if it gets copied to the BIN folder everytime.
D3m0n1CMoNkEy 27-Nov-13 11:29am    
should I connect the EF to the database in the SQLExpress folder in Program files instead of the one in the project folder?
D3m0n1CMoNkEy 27-Nov-13 11:53am    
I changed the property "Copy To Output Directory" from 'Copy Always' to 'Copy if newer', that seems to have fixed the problem, but is it good enough?
D3m0n1CMoNkEy 27-Nov-13 14:41pm    
Its seems changing the "Copy To Output Directory" doesn't work

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