首页 > 解决方案 > 是否可以将 sql clr 函数重写为 sql 存储过程?

问题描述

我在我的项目中使用带有 sql clr 用户定义函数的 sql clr 程序集。例如:

[SqlFunction]
public static SqlString InsertCampaignRecipients(SqlString url) 
{
    var rowData = string.Empty;
    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        var response = client.GetAsync(new Uri(url.Value)).Result;

        if (response.IsSuccessStatusCode)
        {
            var result = response.Content.ReadAsStringAsync().Result;

            if (result.IndexOf(@"""Exception"":null}") > 0) //success
            {
                rowData = "success";
            }
            else
            {
                rowData = string.Empty;
            }
        }
        else
        {
            rowData = string.Empty;
        }
    }
    return rowData;
}

但我想在 clr 不支持的 Azure 上迁移。解决办法是什么?是否可以将 sql clr 函数重写为 sql 存储过程之类的?

标签: sql-serverstored-proceduresazure-sql-databaseuser-defined-functionssqlclr

解决方案


所以你想直接从 T-SQL 发出一个 HTTP 请求。那是不能做的,对不起!


推荐阅读