【发布时间】:2015-02-08 19:07:47
【问题描述】:
我正在尝试使用 C# 在我的 WPF 应用程序中备份选定的数据库。我认为代码很好,但是当备份运行时,我得到了这个错误:
自从收到该错误后,我尝试通过 C# 将文件夹权限授予所有人,但我仍然遇到同样的问题。任何帮助将不胜感激。提前致谢。
这是我的代码:
DirectorySecurity sec = Directory.GetAccessControl(backupFolder);
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(backupFolder, sec);
List<string> dbNameList = GetDatabaseList();
if (dbNameList != null)
{
SqlCommand oCommand = null;
SqlConnection oConnection = null;
foreach (string dbName in dbNameList)
{
string command = @"BACKUP DATABASE " + dbName + " TO DISK='" + backupFolder + "'";
oConnection = new SqlConnection(ConnectionString);
if (oConnection.State != ConnectionState.Open)
oConnection.Open();
oCommand = new SqlCommand(command, oConnection);
oCommand.ExecuteNonQuery();
}
oConnection.Close();
}
【问题讨论】:
标签: c# sql security permissions database-backups