简体   繁体   English

SQL 服务器备份到共享文件夹

[英]SQL server backup to shared folder

I'm trying to make a backup to a network shared folder with the following code:我正在尝试使用以下代码备份到网络共享文件夹:

string filePath = ("\\pc-usuario\folder\backup\backup.bak")
string connectionString = String.Format(@"Data Source={0};Initial Catalog={1};Integrated Security=True;MultipleActiveResultSets=True", server, database);

using (var connection = new SqlConnection(connectionString))
{
    var query = String.Format("BACKUP DATABASE [{0}] TO DISK='{1}'", database, filePath);

    using (var command = new SqlCommand(query, connection))
    {
        connection.Open();
        command.CommandTimeout = 1800;
        command.ExecuteNonQuery();
    }
}

Got the following error:得到以下错误:

The backup device cannot be opened.无法打开备份设备。 Operating system error 5(Access denied.).操作系统错误 5(拒绝访问。)。

If I try it with SQLExpress the same error happens.如果我用 SQLExpress 尝试它,也会发生同样的错误。 What am I missing?我错过了什么?

You havent given the database backup a file name, only a file path你没有给数据库备份一个文件名,只有一个文件路径

Eg the final code should read例如,最终代码应为

backup database wibble to disk = '\\pc-usuario\folder\backup\wibble.bak'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM