I have create a CLR function like this
public class GETJSONFROMURL
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString GETData(SqlString URL)
{
SqlString Data = "N/A";
using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString(new Uri(URL.ToString()));
// Now parse with JSON.Net
JObject o = JObject.Parse(json);
Data = (string)o["Data_results"]["MyData"];
}
return Data;
}
}
and made a function in Sql Like this
CREATE ASSEMBLY GetDataURL
FROM 'C:\GETJSONFROMURL.dll'
WITH PERMISSION_SET = EXTERNAL_ACCESS
CREATE FUNCTION GetDataURL (@URL NVARCHAR(MAX))
RETURNS NVARCHAR(MAX) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME GetDataURL.GETJSONFROMURL.GETData
when I select this function in query window I get result very fast under 0.03 sec
SELECT [dbo].[GetDataURL] ('http://www.Testserver.com/123')
but when I call this function as multiple call , like inside Triggers after insert something call that select I get delay for get result .
can you please help me to create an asynchronous function which is when I call inside sql as multiple call didn't get delay for returning result .
thanks