gpt4 book ai didi

c# - C#语句备份SQL Server数据库

转载 作者:太空宇宙 更新时间:2023-11-03 11:01:30 25 4
gpt4 key购买 nike

我想通过 C# 语句为我在我的应用程序上工作的数据库创建一个备份。

这是我的代码:

SqlConnection con = new SqlConnection(Connection.GetConnection());
SqlCommand command = new SqlCommand();

command.CommandText = "backup database [Pharmacy Database]to disk ="+"'"+path +"'";
command.CommandType = CommandType.Text;
command.Connection = con;

con.Open();
command.ExecuteNonQuery();
con.Close();

并给我一个错误:

Cannot open backup device 'C:/Users/Abo Sala7/Desktop'.Operating system error 5 (failed to retrieve text for this error. Reason:15105).
BACKUP DATABASE is terminating abnormally.

最佳答案

可能问题是您的 SQL 服务的 ServiceUser 没有写入定义文件夹的权限 - 该服务正在执行备份 - 因此该用户必须对目标文件夹具有所需的权限。 (错误 5 == 拒绝访问)

关于c# - C#语句备份SQL Server数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17574173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com