验证或调试天蓝色混合连接

问题描述 投票:0回答:1

我有一个Azure功能运行与内部服务器的混合连接。一切都很好。将来,我们将在多个位置拥有多个混合连接,并且它们可能具有相同的服务器名称和端口组合。

在执行SQL操作之前,有没有办法验证(或调试)正在使用的混合连接的服务总线命名空间或UserMetadata属性?

这是来自函数app的run.csx:

#r "System.Data"


using System.Net;
using System.Collections.Generic;
using System.Configuration;
using Newtonsoft.Json;
using System.Data.SqlClient;
using System.Text;


public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");
    string connectionString = "Server=MyServerName;Initial Catalog=BillingDB;";
    string queryString = "select top 2 * from Billing";

    List<Billing> bills = new List<Billing>();
    SqlConnection conn = new SqlConnection(connectionString);

    conn.Open();

    /***************
    Here is where I would like to be able to verify/validate 
    the namespace or UserMetadata of the hybrid connection so that I'm sure
    we're connecting to the desired database. "Server" in the connection string
    is not enough in our case.
    ******************/


    SqlCommand DBCmd = new SqlCommand(queryString, conn);
    SqlDataReader myDataReader;
    myDataReader = DBCmd.ExecuteReader();

    while (myDataReader.Read())
        {
            bills.Add(new Billing
            {
                Student_ID = Convert.ToInt32(myDataReader[0]),
                Transaction_Number = Convert.ToInt32(myDataReader[1]),
                Log = myDataReader[2].ToString(),
                Amount_Owed = Convert.ToDecimal(myDataReader[3])
            }
            );
        }

    myDataReader.Close();
    conn.Close();

    var json = JsonConvert.SerializeObject(bills);
    log.Info("json: " + json);

    return req.CreateResponse(HttpStatusCode.OK,json);

}




public class Billing {
    public int Student_ID { get; set; }
    public int Transaction_Number { get; set; }
    public string Log { get; set; }
    public decimal Amount_Owed { get; set; }
}
azure-web-sites azure-functions azure-servicebusrelay azure-hybrid-connections
1个回答
0
投票

我最终能够通过向Azure资源管理器REST API发出GET请求来解决这个问题(通过单击“应用程序设置”中的“资源管理器”,它提供了调用以及预期响应主体所需的URL)。除此之外,还需要创建Active Directory应用程序以获取访问资源的令牌。

https://management.azure.com/subscriptions/{subscriptionid}/resourceGroups/{resourcegroupname}/providers/Microsoft.Web/sites/{functionname}/hybridConnectionRelays?api-version=2016-08-01

这将返回一个JSON对象,其中列出了“连接”到各个应用程序/功能应用程序的混合连接的属性。

© www.soinside.com 2019 - 2024. All rights reserved.