1

In my C# windows app using sqlite database, i observed each time i run the application and insert new records into the database, the records will be saved as long as the application is still running, but when i stopped the application, the records will be wiped out(deleted) from the database while using this connection string:

<add name="PITADatabaseConnectionString" connectionString="Data Source=|DataDirectory|\App_Data\PITApplication.SQLite3Db; Version=3;" providerName="System.Data.Sqlite" />

When i change the connection string to:

<add name="PITADatabaseConnectionString" connectionString="Data Source=C:\SqLite\Gui\SQLiteStudio\PITApplication.SQLite3Db; Version=3;"
  providerName="System.Data.Sqlite" />

and save new records, it will be saved permanently and not deleted. I don't know what the issue is, i added the database to a folder in my application through add new items context menu, after adding the database to my application i set Build Action property to Content, and Copy to output directory property to Copy always.

i will appreciate your kind assistance.

UwakPeter
  • 341
  • 2
  • 6
  • 26
  • please i will appreciate if you could provide me with the link to its solution, thanks – UwakPeter Apr 13 '17 at 06:59
  • You need only to change the property Copy To Output Directory. – Steve Apr 13 '17 at 07:05
  • i have done that, yet no luck! – UwakPeter Apr 13 '17 at 07:14
  • Did you check if the database in the **youprojectfolder\bin\debug\app_data\PITApplication.SQLite3Db** contains the missing records before restarting a new debug session? – Steve Apr 13 '17 at 07:20
  • yes, no record there as well – UwakPeter Apr 13 '17 at 08:11
  • I still think that this is a duplicate of this one http://stackoverflow.com/questions/17147249/why-saving-changes-to-a-database-fails/17147460#17147460 however given your comments above I have reopened the question – Steve Apr 13 '17 at 08:27
  • you should check what path do you get from your connection string. check this out for more info: http://stackoverflow.com/questions/12266924/how-do-i-read-the-current-path-of-datadirectory-from-config-settings – Mightee Apr 13 '17 at 09:38

1 Answers1

0

I was able to resolve this issue by going to application properties window, under settings i added a connection string that points to the connection string in the app.config file. I also set the copy to output directory property of the database to copy if newer, and the issue was resolved, thanks to everyone that contributed.

UwakPeter
  • 341
  • 2
  • 6
  • 26