Access API from Stored Procedure in SQL Server


This document describes how to call any API with POST, GET, PUT and DELETE methods from stored procedure. For example, if we want to send email from SQL Server using stored procedure but don’t want to use inbuild functionality of SQL Server but to use any third party API.
To make it working (For the purpose of testing) first I created API you can get the API of GET and POST http://mongobox.azurewebsites.net/swagger
Now created a CLI Project in Visual Studio and created a method called SendMail which is accepting few parameters like WebURL, EmailTo,EmailBody,EmailSubject. See below image.




Now as I am utilizing the POST method API, so I need to pass various parameters in that API and I am passing it to API with given method: (Name, Age and other params are according to API we can use any params as per need of API)



Now, I need to build and publish this code in folder to get DLL file which will be used as assembly file in SQL server see below image (We need to add other dependent DLLs as well.)


Now created a Stored Procedure as


To call this stored procedure use below syntax:





Comments

Popular posts from this blog

DTS package conversion in SSIS to use in SQL 2012 and SQL 2016

Infinite Scroll in Asp.Net C# using Javascript without Third party Plugin

Add Custom Tags in Web config file in ASP .Net