尝试在azure上创建弹性池时发生异常
问题描述:
我需要为programmaticaly创建一个弹性池。这里是我的代码:尝试在azure上创建弹性池时发生异常
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属性是):
你能帮我解决这个问题吗?图书馆对于CRUD还不稳定吗?
答
我也可以用.net core 2.0重现它。而且我们也可以使用另一个SO thread中提到的方式来解决它,即使我们没有应用程序见解。更多细节请参考blog。在你的情况下,我们需要改变dtu等于或大于,基本版本至少 dtu。以下是我的详细步骤:
1.创建.net core 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);
}
3,我们需要在DTU更改为基本版本。
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.在本地测试,它在我身边正常工作。
5.检查从在Azure门户
答
有时对API的错误消息是有点误导。
您是否尝试将eDTU设置为50?
这是你想要的最低eDTU的,你可以使用基本层来创建:
https://azure.microsoft.com/en-us/pricing/details/sql-database/
+0
我也在我的回答中提到了这一点。你也可以对此发表评论。 –
杜佩? https://stackoverflow.com/questions/45167981/azure-fluent-api-error-creating-sql-server-missing-x-ms-request-id-header – Caramiriel
谢谢先生,我已经看到了这个问题,但因为我没有ApplicationInsights,我自己也许会说别的,我会在这个问题中添加一个评论,提到即使您没有AppInsight,也可能导致这种情况。 – yeska