尝试在天蓝色上创建弹性池时出现异常

时间:2017-09-08 16:11:32

标签: c# azure azure-sql-database azure-sdk-.net

我需要创建programmaticaly弹性池。这是我的代码:

        var credentials = new Microsoft.Rest.TokenCredentials(await GetToken());

        var sqlclient = new Microsoft.Azure.Management.Sql.SqlManagementClient(credentials) { SubscriptionId = subscriptionId };

        var sqlServer = (await sqlclient.Servers.GetWithHttpMessagesAsync("MyApp-com","myApp-com")).Body;

        var azurePool = (await sqlclient.ElasticPools.CreateOrUpdateWithHttpMessagesAsync("MyApp-com",sqlServer.Name,"poolname", new Microsoft.Azure.Management.Sql.Models.ElasticPool(sqlServer.Location,  edition:"Basic",dtu:5))).Body;

我正在使用:

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Resources" Version="2.20.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.6.0-preview" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.10" />

我在最后一行得到了这个例外:

Microsoft.Rest.Azure.CloudException occurred
  HResult=0x80131500
  Message=Invalid value for header 'x-ms-request-id'. The header must contain a single valid GUID.
  Source=<Cannot evaluate the exception source>
  StackTrace:
   at Microsoft.Azure.Management.Sql.ElasticPoolsOperations.<BeginCreateOrUpdateWithHttpMessagesAsync>d__15.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.Sql.ElasticPoolsOperations.<CreateOrUpdateWithHttpMessagesAsync>d__7.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

正如你在这里看到的,'x-ms-request-id'不是有效的guid(但是RequestId属性是):enter image description here

你可以帮我这个吗?库是否对CRUD不稳定?

2 个答案:

答案 0 :(得分:2)

我也可以使用.net core 2.0重现它。我们也可以使用另一个SO thread中提到的方式来解决它,即使我们没有应用程序见解。更多详情请参阅blog。在您的情况下,我们需要将dtu更改为等于或大于 50 ,对于基本版本至少 50 dtu。以下是我的详细步骤:

1.创建.net核心2.0 Asp.net项目。

2.在 Startup.cs 文件中添加以下代码。

 private void DisableCorrelationIdHeaders(IServiceCollection services)
        {
            var module = services.FirstOrDefault(t => t.ImplementationFactory?.GetType() == typeof(Func<IServiceProvider, DependencyTrackingTelemetryModule>));
            if (module != null)
            {
                services.Remove(module);
                services.AddSingleton<ITelemetryModule>(provider => new DependencyTrackingTelemetryModule { SetComponentCorrelationHttpHeaders = false });
            }
        }

 public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddApplicationInsightsTelemetry();
            DisableCorrelationIdHeaders(services);
        }

enter image description here

3.我们需要将基本版本的dtu更改为 50

var azurePool = (await sqlclient.ElasticPools.CreateOrUpdateWithHttpMessagesAsync("MyApp-com",sqlServer.Name,"poolname", new Microsoft.Azure.Management.Sql.Models.ElasticPool(sqlServer.Location,  edition:"Basic",dtu:50))).Body;  //at least 50 for basic version

4.在本地测试,它在我身边正常工作。

enter image description here

5.从Azure门户网站查看

enter image description here

答案 1 :(得分:0)

有时API上的错误消息有点误导。

您是否尝试将eDTU设置为50?

这是您可以用于创建的基本层的最小eDTU:

https://azure.microsoft.com/en-us/pricing/details/sql-database/