且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用C#错误创建SQL Server(网络模式)数据库的备份:备份数据库异常终止

更新时间:2023-02-12 23:00:18

看起来你正试图将数据库的备份放在本地机器上的文件夹中。如果你懒得阅读它,错误是非常明显的。 SQL Server根本没有对您的计算机的权限,因此它无法在那里编写备份。
It looks like you're trying to put the backup of the database in a folder on your local machine. The error is pretty obvious if you bother to read it. The SQL Server does not have permissions to your machine at all so it can't write the backup there.


正如Dave所说,这是一个文件夹问题。

如果你看一下这个:用C#备份SQL数据库 [ ^ ]它提供了我使用的代码,并解释了您需要注意的缺陷 - 包括(但不限于)您遇到的文件夹访问问题。



并且永远不会连接字符串以形成SQL命令 - 甚至不是BACKUP - 您可以将代码保持为SQL注入。始终使用参数化查询!
As Dave says, it's a folder problem.
If you have a look at this: Backing up an SQL Database in C#[^] it provides the code I use, and explains the pitfalls you have to look out for - whihc includes (but isn't limited to) the folder access problem you are having.

And never concatenate strings to form an SQL command - not even a BACKUP - you leave your code wide open to SQL Injection. Always use a parameterised query!