为什么我不能在桌面上保存数据库备份?

问题描述 投票:0回答:0

我想在 C# Windows 窗体中从我的 SQL Server 数据库中获取备份。但是我有一些问题。当我想用不同的数据库名称保存备份文件时,我的应用程序崩溃并出错。此外,我无法将备份保存在桌面上,但所有其他位置都没有错误。 这是我的备份代码:(我使用

FolderBrowserDialog
,因为用户输入了数据库主名称以外的任何名称,程序会出错)。

            string result;
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            BLLBackupRestor bLL = new BLLBackupRestor();


            dialog.ShowDialog();
            if (dialog.SelectedPath != "")
            {
                result = bLL.backUp(dialog.SelectedPath);
                if (result == "true")
                {
                    MessageBox.Show(message.messageSettingBackUpDataBase(), "",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, message.messageBoxAlign());
                    

这是我尝试将备份保存在桌面上时遇到的错误:任何其他地址或文件夹都没有问题。

"System.Data.SqlClient.SqlException (0x80131904): 无法打开备份 设备 'C:\Users\sadegh\Desktop\Custom_Category.bak'。操作 系统错误 5(访问被拒绝。)。 备份数据库正在终止 不正常的。 在 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常, 布尔 breakConnection, Action

1 wrapCloseInAction)\r\n   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
在 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler、SqlDataReader 数据流、 BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj, Boolean& dataReady) 在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(字符串 方法名称、布尔异步、Int32 超时、布尔异步写入) 在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 完成,字符串方法名称,布尔 sendToPipe,Int32 超时, Boolean&usedCache, Boolean asyncWrite, Boolean inRetry) 在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 在 DataAccessLayer.BackUpRestor.backUp(字符串地址) 在 C:\Users\sadegh\source epos\Custom_Category\DataAccessLayer\BackUpRestor.cs:行 22 ClientConnectionId:02e41dc3-d9b0-4c5c-baa1-089a79463b37 错误 编号:3201,状态:1,等级:16"

c# sql-server winforms database-backups
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.