Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

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:

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


When i change the connection string to:

XML
<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.

What I have tried:

i have used this connection string:

<add name="PITADatabaseConnectionString" connectionString="Data Source=|DataDirectory|\App_Data\PITApplication.SQLite3Db; Version=3;" providerName="System.Data.Sqlite" />
Posted
Updated 19-Apr-17 5:14am
Comments
Herman<T>.Instance 13-Apr-17 3:45am    
Do you use transactions?
Uwakpeter 13-Apr-17 4:10am    
yes, i am using transaction to save the records, is that the issue?
Herman<T>.Instance 19-Apr-17 3:27am    
It is possible. If the transaction is not (yet) committed when you stop the application, the database will perform a ROLLBACK and thus you miss data.
Richard MacCutchan 13-Apr-17 4:23am    
Most likely the file is being recreated somehow in your IDE or elsewhere in your application.
Uwakpeter 13-Apr-17 4:41am    
how do i know where the record is being recreated?

1 solution

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.
 
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