在这里我创建了C#windos应用程序的安装文件它工作正常,但每当我试图将数据库备份到.bak文件时它显示错误 [英] Here I m created setup file of C# windos application it work good but whenever I m trying to backup the database into.bak file it shows an error

查看:78
本文介绍了在这里我创建了C#windos应用程序的安装文件它工作正常,但每当我试图将数据库备份到.bak文件时它显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误显示: -

c:\附近的错误符号(这是安装后的数据库文件)。

combodatabase是数据库的组合框。

txtdestination是文件对话框路径,其中必须存储.bak文件



我尝试过:



error shows:-
incorrect symbol near c:\(this is the database file after installation).
combodatabase is combobox for database.
txtdestination is file dialog path where have to store the .bak file

What I have tried:

try
{
    SqlConnection cn = new SqlConnection(conn);
    cn.Open();
    if (combodatabase.Text.CompareTo("") == 0 || txtdestination.Text == "")
    {
        MessageBox.Show("Fill all data and try again", "Choose option");
    }
    else
    {
        SqlCommand cmd = new SqlCommand("BACKUP DATABASE '"+combodatabase.Text+"' TO DISK='"+txtdestination.Text+".BAK' ",cn);
                    
        cmd.ExecuteNonQuery();
        MessageBox.Show("suceessfully backuped");
    }
}
catch (SqlException ee)
{
    MessageBox.Show("" + ee.Message);
}

推荐答案

有很多可能的原因,包括目标文件夹上的访问冲突。

看看这里:用C#备份SQL数据库 [ ^ ]它解释了问题,并显示了我使用的代码。
There are loads of possible reasons, including access violations on the destination folder.
Have a look here: Backing up an SQL Database in C#[^] it explains teh problems, and shows the code I use.


这篇关于在这里我创建了C#windos应用程序的安装文件它工作正常,但每当我试图将数据库备份到.bak文件时它显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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