question

MrFlinstone-1451 avatar image
0 Votes"
MrFlinstone-1451 asked SeeyaXi-msft commented

How to write a REST API that will get or put onto a SQL server database

Hi All.


I am looking to create an api such that a record can be written into a SQL server database. It will simply call a stored procedure with some data received. The api will return a status code to confirm if the insert has been successful or not.

The environment is on-premise (my laptop) and as such cannot use Azure functionality.

sql-server-generalwindows-server-powershellpartner-center-api
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Why use REST and not the Invoke-SqlCommand cmdlet?

There are plenty of examples of using stored procedures from PowerShell and using their output (if you need it). I just looked for "powershell use sql stored procedure"!

0 Votes 0 ·

Hi @MrFlinstone-1451 ,

We have not received a response from you. Did the reply could help you? If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.

Best regards,
Seeya

0 Votes 0 ·
SeeyaXi-msft avatar image
0 Votes"
SeeyaXi-msft answered SeeyaXi-msft edited

Hi @MrFlinstone-1451 ,

Please refer to this: https://www.zealousweb.com/calling-rest-api-from-sql-server-stored-procedure/
AND https://hevodata.com/learn/sql-server-rest-api-integration/
Hope these articles are helpful to you.

Best regards,
Seeya


If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hello MrFlinstone,

Runs a script containing statements supported by the SQL Server SQLCMD utility.

The Invoke-Sqlcmd cmdlet runs a script containing the languages and commands supported by the SQL Server SQLCMD utility.

The commands supported are Transact-SQL statements and the subset of the XQuery syntax that is supported by the database engine.

This cmdlet also accepts many of the commands supported natively by SQLCMD, such as GO and QUIT.

https://docs.microsoft.com/en-us/powershell/module/sqlserver/invoke-sqlcmd?view=sqlserver-ps

Hope this answers all your queries, if not please do repost back.
If an Answer is helpful, please click "Accept Answer" and upvote it : )

Regards,

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.