删除并复制数据库sqlite C# [英] Delete and copy database sqlite C#

查看:112
本文介绍了删除并复制数据库sqlite C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用sqlite数据库编写了ac#应用程序。我将项目设置中的数据库地址保存为字符串:



数据源= bazarganidb.db;版本= 3



我在我的程序中使用它如下:

 SQLiteConnection con = new SQLiteConnection(Properties.Settings) .Default.ConnectionString); 



现在如何删除此数据库并替换为另一个数据库以恢复备份数据库?



我尝试过:



我使用以下代码备份我的数据库:

 private void button1_Click(object sender,EventArgs e)
{
using(var source = new SQLiteConnection(Data
Source = bazarganidb.db; version = 3))
使用(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);
}
}



但我不知道如何恢复

解决方案

SQLite数据库是磁盘上的单个文件,因此只需复制该文件进行备份,并在不需要时将其删除,不需要使用 SQlitexxx 界面。

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

解决方案

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.


这篇关于删除并复制数据库sqlite C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆