以下是我自己写的数据库的备份程序
private void button1_Click(object sender, System.EventArgs e)
{
    SqlConnection myConnection;
    myConnection = new SqlConnection("server=(local);database=model;Trusted_Connection=yes");

    string insertCmd ="backup database model to disk='F:\\bf.mdb'";
    SqlCommand myCommand = new SqlCommand(insertCmd,myConnection);

    myCommand.Connection.Open();

    try
    {
        myCommand.ExecuteNonQuery();
        MessageBox.Show("添加成功");
    }
    catch(SqlException ex)
    {
        MessageBox.Show("插入数据错误");
    }

    myCommand.Connection.Close();
}
已经得到了预期的结果,在指定的路径下可以找到相应的文件了,我个人认为成功了。

以下是我自己写的数据库的还原程序
private void button2_Click(object sender, System.EventArgs e)
{
    SqlConnection myConnection;
    myConnection = new SqlConnection("server=(local);database=model;Trusted_Connection=yes");

    string insertCmd ="restore database model from disk='F:\\bf.mdb'";
    SqlCommand myCommand = new SqlCommand(insertCmd,myConnection);

    myCommand.Connection.Open();

    try
    {
        myCommand.ExecuteNonQuery();
        MessageBox.Show("添加成功");
    }
    catch(SqlException ex)
    {
        MessageBox.Show("插入数据错误"+ex.Message.ToString());
    }

    myCommand.Connection.Close();
}
运行结果错误了,给出的提示大概是说数据库正在运行,不能还原数据库,请教高手我该怎么改上面的程序,使得程序运行成功。谢谢。加分。