我按照快速指南从.Net(http://www.bidn.com/blogs/ShawnHarrison/ssis/2134/access-denied-during-database-backup)备份了SQL Server数据库。简而言之,更新的SQL服务(服务)>属性>登录标签>内置帐户public void BackupDatabase()
{
try
{
Backup sqlBackup = new Backup
{
Action = BackupActionType.Database,
BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString(),
BackupSetName = "Archive"
};
ServerConnection connection = new ServerConnection
{
ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString
};
DatabaseName = (new SqlConnectionStringBuilder(connection.ConnectionString)).InitialCatalog;
FileName = DatabaseName + "_" + DateTime.Now.ToString("yyyyMMdd-hhmmss") + ".bak";
AbsolutePath = DestinationPath + FileName;
BackupDeviceItem deviceItem = new BackupDeviceItem(AbsolutePath, DeviceType.File);
sqlBackup.Database = DatabaseName;
Server sqlServer = new Server(connection);
Microsoft.SqlServer.Management.Smo.Database db = sqlServer.Databases[DatabaseName];
sqlBackup.Initialize = true;
sqlBackup.Checksum = true;
sqlBackup.ContinueAfterError = true;
sqlBackup.Devices.Add(deviceItem);
sqlBackup.Incremental = false;
sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
sqlBackup.FormatMedia = false;
sqlBackup.SqlBackup(sqlServer);
Success = true;
Result = string.Format("<i>{0}</i> was successfully backed up to the following location: <i>{1}</i>", FileName, DestinationPath);
}
catch (Exception ex)
{
ExceptionLogHelper.AddExceptionLog("Helper.DatabaseHelper.BackupDatabase", ex.Message.ToString(), ex.StackTrace.ToString());
Success = false;
Result = string.Format("{0}, {1}", ex.Message.ToString(), ex.InnerException.InnerException.Message.ToString());
}
}
。
我想知道如何避免直接通过Windows更改并在我的代码中指定某种类型的身份验证?假设我无法访问服务(通过RDP等)。
我的代码如下:
var awsOptions = Configuration.GetAWSOptions();
awsOptions.Credentials = new EnvironmentVariablesAWSCredentials();
services.AddDefaultAWSOptions(awsOptions);
services.AddAWSService<IAmazonS3>();