SQL Server 数据库更新调用外部HTTP请求
sql server developer 当插入数据和update数据的时候能否调用http请求
https://learn.microsoft.com/zh-cn/sql/relational-databases/clr-integration/database-objects/getting-started-with-clr-integration?view=sql-server-ver15&tabs=cs
步骤 2: 创建 CLR 程序集
set Path=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%path%
csc /target:library HttpClientHelper.cs
https://blog.csdn.net/KOBO_24/article/details/115907693
.NET4.0缺少System.Net.Http组件
步骤 1: 启用 CLR 集成
sp_configure 'clr enabled', 1;
RECONFIGURE;
步骤 3: 将 CLR 程序集加载到 SQL Server
ALTER DATABASE weight20 SET TRUSTWORTHY ON
CREATE ASSEMBLY HttpClientAssembly
FROM 'C:\ClassLibrary1\HttpClientHelper.dll'
WITH PERMISSION_SET = UNSAFE;
Q 针对程序集“HttpClientHelper”的 CREATE ASSEMBLY 失败,因为程序集“HttpClientHelper”不受信任。满足以下两个条件之一时信任程序集: 程序集已使用其对应登录名具有 UNSAFE ASSEMBLY 权限的证书或非对称密钥加以签名,或使用 sp_add_trusted_assembly 信任程序集。
A ALTER DATABASE weight20 SET TRUSTWORTHY ON
步骤 4: 创建 SQL Server 存储过程或函数来调用 CLR 代码
CREATE PROCEDURE MakeHttpRequest
@url NVARCHAR(1024)
AS
EXTERNAL NAME HttpClientAssembly.[HttpClientHelper].MakeHttpRequest;
CREATE TRIGGER trgAfterUpdate
ON Employee
FOR UPDATE
AS
BEGIN
DECLARE @url NVARCHAR(255) = 'https://example.com/endpoint';
EXEC MakeHttpRequest @url;
END;