Today, when backing up the database with SMO, the following exception is reported:
Backup failed for server "server name". (MICROSOFT.SQLSERVER.SMO)
Additional Information: System.Data.SqlClient.SqlError: Unable to open backup device ' C:\zyl.bak '. Operating system error 5 has occurred (access denied. )。 (MICROSOFT.SQLSERVER.SMO)
Solution:
There are usually two reasons for these exceptions:
1.SQL Server cannot place the backup file under the root directory, it must be placed in a non-root directory, or it will be an error.
1 string @" C:\BackUp\ "; // the folder where the backed up data is stored (correct)
2. Check if the backup path exists, the database will not help you to create a non-existent path, you need to create a good path, and then back up the time to specify the path;
Backup workaround for Server "server name" failure