如何在ASP.NET中备份sqlserver数据库? [英] How to do backup of sqlserver database in ASP.NET?

查看:90
本文介绍了如何在ASP.NET中备份sqlserver数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ASP.NET中备份数据库,但遇到错误:
无法在sysdatabases中找到数据库"SMSManager"的条目.找不到使用该名称的条目.确保正确输入名称.BACKUPDATABASE异常终止.

请帮帮我.
谢谢

I am trying to do backup of database in ASP.NET but I face with error:
Could not locate entry in sysdatabases for database ''SMSManager''. No entry found with that name. Make sure that the name is entered correctly.BACKUP DATABASE is terminating abnormally.

Please help me.
Thank you

推荐答案

我想您正在尝试以编程方式进行备份

上面的错误消息表明数据库服务器中不存在目标数据库(您尝试从中进行备份).可能是您为数据库名称提供了错误的名称,或者提供了其他错误的输入值.

但是,如果您尝试进行手动备份,请 [
I guess you are trying to take backup programmatically

The above error message indicates the target database (Which you are trying to take backup from) doesn''t exists in the database server. May be you are providing a wrong name for the database name, or giving some other wrong input values.

However, if you are trying to take manual backup, This[^] might help you.


C#代码:
C# code:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SmsManagerconnectionStrings"].ConnectionString);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "FullBackup";
        cmd.CommandType = CommandType.StoredProcedure;
        con.Open();
        cmd.Parameters.AddWithValue("@DataPath", Server.MapPath("~/uploads/dow.bak"));
        cmd.ExecuteNonQuery();
        con.Close();


与存储过程fullbackup:


with stored procedure fullbackup:

ALTER  PROCEDURE [dbo].[FullBackup]
(@DataPath Nvarchar(Max))
AS
    BACKUP DATABASE SMSManager TO DISK=@DataPath with NOFORMAT,NOINIT,NAME=N''SMSManager.mdf-Full Database Backup'',SKIP,NOREWIND,NOUNLOAD,STATS=10


谢谢


这些类似的线程讨论应该可以为您提供帮助.看看:
链接1 [链接2 [ ^ ]
如果需要,只需Google错误,您将获得更多讨论类似问题的链接.
These similar thread discussions should help you out. Have a look:
Link 1[^]
Link 2[^]
If needed, just Google the error and you will get more links discussing similar issue.


这篇关于如何在ASP.NET中备份sqlserver数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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