6

I'm trying to create a new SQL Server with the Azure Fluent API (https://github.com/Azure/azure-sdk-for-net/tree/Fluent) but I always get a Microsoft.Rest.Azure.CloudException. Everything else (Creating Storage Account, App Services, Resource Groups) works fine - it's just the SQL part which does not work.

ISqlServer sqlServer = await Azure.SqlServers
                    .Define(serverName)
                    .WithRegion(regionName)
                    .WithExistingResourceGroup(rgName)
                    .WithAdministratorLogin(administratorLogin)
                    .WithAdministratorPassword(administratorPassword)
                    .WithNewElasticPool(elasticPoolName, elasticPoolEdition)
                    .CreateAsync();

But when trying to create the server I got an exception:

{Microsoft.Rest.Azure.CloudException: Invalid value for header 'x-ms-request-id'. The header must contain a single valid GUID.
   at Microsoft.Azure.Management.Sql.Fluent.ServersOperations.<CreateOrUpdateWithHttpMessagesAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.Sql.Fluent.ServersOperationsExtensions.<CreateOrUpdateAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.Sql.Fluent.SqlServerImpl.<CreateResourceAsync>d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.Creatable`4.<Microsoft-Azure-Management-ResourceManager-Fluent-Core-ResourceActions-IResourceCreator<IResourceT>-CreateResourceAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Core.DAG.CreatorTaskItem`1.<ExecuteAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Core.DAG.TaskGroupBase`1.<ExecuteNodeTaskAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at XircuitAPI.Controllers.AzureSqlServerController.<Create>d__9.MoveNext() in C:\Users\ThimoBuchheister\Documents\Code\Xircuit\xircuit\XircuitAPI\Controllers\AzureSqlServerController.cs:line 235}
1
  • 2
    I solved the problem with a configuration change in Apllication Insights as mentioned in the answer by @Siphamandla. If this does not solve it for you try to check if there are HTTP headers added to the request. Commented Jul 23, 2017 at 16:51

4 Answers 4

5

Okay i have solved my problem, after using fiddle to trace my http request i discovered that, Application Insights added headers to my request to the AAD app. So i total removed Application Insights and im back online. Hope it helps you. Look at this. if you want to continue using Application Insight check this out disable application insight

Sign up to request clarification or add additional context in comments.

1 Comment

Even if you don't have application insights used in your asp.net core app, you should disable it.
4

All you had to do was to exclude a domain or other options that are written in this link.

https://blog.wille-zone.de/post/disable-application-insights-correlation-id-headers-on-httpclient-requests-in-aspnet-core/

    var modules = app.ApplicationServices.GetServices<ITelemetryModule>();
    var dependencyModule = modules.OfType<DependencyTrackingTelemetryModule>().FirstOrDefault();

    if (dependencyModule != null)
    {
        var domains = dependencyModule.ExcludeComponentCorrelationHttpHeadersOnDomains;
        domains.Add("management.azure.com");
    }

1 Comment

Used this solution to keep Application Insights and DependencyTracking in my application. Works very well. I'm wondering why this domain is not included in the configuration file by default but there is probably a good reason :).
2

For those not on .NET Core but on Web API or ASP.NET MVC 5, reach for the modules like this:

var dependencyModule = Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryModules.Instance.Modules
    .OfType<Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule>()
    .FirstOrDefault();

if (dependencyModule != null)
{
    var domains = dependencyModule.ExcludeComponentCorrelationHttpHeadersOnDomains;
    domains.Add("management.azure.com");
}

Comments

0

I can't repro the issue that you mentioned with Microsoft.Azure.Management.Sql.Fluent SDK version 1.1.3. The following is my detail steps:

preparation

Registry an AD application and assgin application to corresponding role, more details please refer to Azure official tutorials. After that we can get tenantId, appId, secret key from the Azure Portal.

Steps:

1.Create a .net core C# console project.

2.Reference the Microsoft.Azure.Management.Sql.Fluent SDK, more details please refer to the following screenshot

3.Add the following code to the Program.cs file.

string clientId = "xxxxxxx";
string secretKey = "xxxxxxx";
string tenantId = "xxxxxxx";
var credentials = new AzureCredentials(new ServicePrincipalLoginInformation { ClientId = clientId, ClientSecret = secretKey }, tenantId, AzureEnvironment.AzureGlobalCloud);
var azure = Azure
            .Configure()
            .Authenticate(credentials)
            .WithDefaultSubscription();
var serverName = "tomtestsqlazure";//test sql name
var regionName = Region.AsiaEast.ToString(); //region name
var administratorLogin = "tom";
var administratorPassword = "xxxxxxx";
var rgName = "xxxxx"; //resource group name
var elasticPoolName = "testelastic"; 
var elasticPoolEdition = "standard";
ISqlServer sqlServer =  azure.SqlServers
.Define(serverName)
.WithRegion(regionName)
.WithExistingResourceGroup(rgName)
.WithAdministratorLogin(administratorLogin)
.WithAdministratorPassword(administratorPassword)
.WithNewElasticPool(elasticPoolName, elasticPoolEdition)
.CreateAsync().Result;

4.Debug from local and catch the request with fiddler.

enter image description here

enter image description here

5.Check it from the Azure portal.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.