1

What I'm trying to do simply is execute a CLR Stored Procedure from SQL Server 18 which is aiming to a database project created in Visual Studio 2019, sending a parameter (an URL), to try to be executed into VS, but when the WebRequest object receives my parameters, seems the WebRequest doesn't do nothing, and what I need is to call that URL from another project.

I have tried with a library class in another project, putting there a HttpClient object and it works succesfully. Another thing I've tried is creating a library class into the datbase project and try to interconnect them, to try to call the method I know works (with HttpClient object) but neither let me references it.

  • SQL SERVER statements:
ALTER DATABASE SellerCenter SET TRUSTWORTHY ON
------------------------------------------------
EXEC sp_configure 'clr enabled', 1
GO
    RECONFIGURE
GO
--------------------------------
CREATE ASSEMBLY [CLR_GetFeed]
    FROM 'D:\CLR_SPs\SQL_CLRs.dll'
    WITH PERMISSION_SET = EXTERNAL_ACCESS
GO
-----------------------------
CREATE PROCEDURE sp_GetFeed
    @url nvarchar(2000)
AS
    EXTERNAL NAME CLR_GetFeed.StoredProcedures.CLR_GetFeed
GO
-------------------------------------------------------------
EXECUTE sp_GetFeed @url = 'https://localhost:44325/api/order'

.NET code:

public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void CLR_GetFeed (SqlString url)
    {
        SqlContext.Pipe.Send(string.Format($"[{url.ToString()}]"));
        WebRequest request = WebRequest.Create(url.ToString());
    }
}

Is here when I try to connect the above method with this lower one, but has been impossible to try to make see the CLR_GetFeed (above) with the GetFeedRedirect(below):

public class RedirectLinks
    {
        private static readonly HttpClient client = new HttpClient();

        public static async System.Threading.Tasks.Task<string> GetFeedRedirect()
        {
            string responseString = await client.GetStringAsync("https://localhost:44325/api/order");

            return responseString;
        }
    }

When I execute the SP (sp_GetFeed) with the parameter (URL), it run succesfully and shows me the URL as a message in the Messages part in SQL Server, but never executes the URL, I mean, I need to call an external service that aims to an API.

3
  • What is the actual error/issue? Also, I don't see where you call into GetFeedredirect. Commented Jun 15, 2019 at 2:20
  • What I really need is to Call a REST API Service from SQL Server using C# SQL CLR, but I'm getting the next error message: Error de solicitud de permiso de tipo 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Commented Jun 17, 2019 at 15:57
  • When, where are you getting this error? Commented Jun 18, 2019 at 8:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.