Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I programmed a c# application with sqlite database.I saved the address of database in setting of project as string :

Data Source=bazarganidb.db;version=3

and i use it in my program as below:
SQLiteConnection con = new SQLiteConnection(Properties.Settings.Default.ConnectionString);

now how can i delete this database and replace with another database to restore backuped database?

What I have tried:

I backuped my database with this code:
private void button1_Click(object sender, EventArgs e)        
{   
using (var source = new SQLiteConnection("Data 
Source=bazarganidb.db;version=3"))
using (var destination = new SQLiteConnection("Data Source=" + textBox1.Text + "/" + DateTime.Now.ToString("yyyyMMdd") + "backup.db"))
    {
        source.Open();
        destination.Open();
        source.BackupDatabase(destination, "main", "main", -1, null, 0);
    }
}

but i dont know about restoring
Posted
Updated 4-Nov-17 20:04pm

1 solution

SQLite databases are a single file on disk, so just copy the file for backup, and delete it when you don't want it, there is no need for using SQlitexxx interface.
 
Share this answer
 
Comments
Member 11727674 6-Nov-17 4:47am    
thanks but i dont know why when i'm delete and copy the backup into debug folder nothing happen and its just for debug folder it hasn't any problem with another folders.can you help me about it?
Mehdi Gholam 6-Nov-17 4:52am    
What is the error?
Make sure the file is not open.
Member 11727674 6-Nov-17 5:15am    
i updated code to this but no error or exception just nothing happen
try
{
string FileToReplace = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), "bazarganidb.db");
File.Delete(FileToReplace);
string OriginalFile =@"D:\bazarganidb.db";
if(File.Exists(FileToReplace))
File.Delete(FileToReplace);
File.Copy(OriginalFile, FileToReplace,true);
}
catch (Exception k)
{
Console.WriteLine(k);
}
Mehdi Gholam 6-Nov-17 5:17am    
What is the value for FileToReplace ?
Member 11727674 6-Nov-17 5:20am    
FileToReplace is the path of file bazargani.db that there is in debug folder of my project and i want to be delete and copy file @"D:\bazarganidb.db" instead of that

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