2017-07-18 13 views
3

我想用Azure Fluent API創建一個新的SQL Server(https://github.com/Azure/azure-sdk-for-net/tree/Fluent),但我總是得到一個Microsoft.Rest.Azure.CloudException 。其他一切(創建存儲帳戶,應用程序服務,資源組)工作正常 - 這只是SQL部分不起作用。創建SQL Server的Azure Fluent API錯誤 - 缺少x-ms-request-id標題

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

但是,試圖創建我有一個異常的服務器時:

{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} 
+2

我解決了在Apllication見解配置變化的問題,由@Siphamandla的答覆中提到。如果這樣不能解決問題,請嘗試檢查是否有HTTP頭添加到請求中。 – Doppelmoep

回答

1

好吧,我已經解決了我的問題,用小提琴來跟蹤我的http請求我發現,應用洞察添加的報頭,以我的請求,AAD應用之後。所以我完全刪除了應用程序見解,並重新聯機。希望它可以幫助你。看這個。如果您想繼續使用Application Insight,請檢查此項 disable application insight

+1

即使您沒有在您的asp.net核心應用程序中使用應用程序見解,也應該禁用它。 – yeska

0

我不能瑞普您使用Microsoft.Azure.Management.Sql.Fluent SDK 1.1.3版本中提到的問題。以下是我的詳細步驟:

準備

註冊的AD應用和assgin應用到對應的角色,更多詳細信息,請參閱Azure official tutorials。之後,我們可以從Azure門戶獲得tenantId,appId,密鑰

步驟:

1.創建一個.NET核心C#控制檯項目。

2.Reference的Microsoft.Azure.Management.Sql.Fluent SDK,詳細信息請參考下面的截圖

3.添加以下代碼,Program.cs文件。

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.從本地調試,並用提琴手接收請求。

enter image description here

enter image description here

5.檢查它在Azure門戶。

enter image description here

2

您只需要排除在此鏈接中寫入的域或其他選項。

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

使用此解決方案將Application Insights和DependencyTracking保留在我的應用程序中。工作得很好。我想知道爲什麼這個域默認不包含在配置文件中,但可能有一個很好的理由:)。 –