Azure SQLManagementClient ResourceNotFound:Uri与任何特定的服务操作都不匹配

时间:2015-03-29 02:59:22

标签: azure

我正在尝试使用管理库以编程方式将Azure SQL数据库导出到blob存储。

SqlManagementClient managementClient = new SqlManagementClient(credentials);
var exportParams = new DacExportParameters()
{
    BlobCredentials = new DacExportParameters.BlobCredentialsParameter()
    {

        StorageAccessKey = tenant.StorageKey,
        Uri = new Uri(String.Format(@"https://" + tenant.StorageName + ".blob.core.windows.net/updatebackups/{0}.bacpac", tenant.DBName + "_" + DateTime.UtcNow.Ticks.ToString()))
    },
    ConnectionInfo = new DacExportParameters.ConnectionInfoParameter()
    {
        ServerName = tenant.DBServer,
        DatabaseName = tenant.DBName,
        UserName = tenant.DBUserName,
        Password = tenant.DBPassword
    }
};

var exportResult = managementClient.Dac.Export(tenant.DBServer, exportParams);

不幸的是,我收到了一个有点模糊的错误:

  

ResourceNotFound:Uri与任何特定的服务操作都不匹配。

我查了一下:

  • 订阅ID
  • 服务器名称(格式为* .database.windows.net)
  • 存储名称(如果重要,则存在容器)

一切似乎都是正确的。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

事实证明,尽管这两个变量都被称为ServerName,但其中一个变量需要一个完整路径,而另一个变量只需要名称。

将存储的值更改为短名称并运行此代码修复它:

SqlManagementClient managementClient = new SqlManagementClient(credentials);
var exportParams = new DacExportParameters()
{
    BlobCredentials = new DacExportParameters.BlobCredentialsParameter()
    {

        StorageAccessKey = tenant.StorageKey,
        Uri = new Uri(String.Format(@"https://" + tenant.StorageName + ".blob.core.windows.net/updatebackups/{0}.bacpac", tenant.DBName + "_" + DateTime.UtcNow.Ticks.ToString()))
    },
    ConnectionInfo = new DacExportParameters.ConnectionInfoParameter()
    {
        ServerName = tenant.DBServer + ".database.windows.net",
        DatabaseName = tenant.DBName,
        UserName = tenant.DBUserName,
        Password = tenant.DBPassword
    }
};

var exportResult = managementClient.Dac.Export(tenant.DBServer, exportParams);

请注意+ ".database.windows.net"