Workaround for xp_cmdshell in Azure SQL Database - azure

Stored procedure in on-premises SQL Server is used to call another app through 'xp_cmdshell'.
Now I am trying to do the same on Azure SQL Database. Of course 'xp_cmdshell' is not supported there, so I need workaround.
I was thinking of using Azure Functions as a bridge between Azure SQL Database and app on VM.
Is it possible to call Azure Function from Azure SQL Database using
stored procedure?
Is it possible to call app on Azure VM from Azure
Function?

Not at the moment. The workaround is to create a Timer-based Azure Function that polls the data every "x" minutes or seconds.
As long the app on Azure VM expose an HTTP endpoint, and you configure the network and the firewall correctly, yes.

The best practice is to use Azure Automate to run tasks on the VM then using a pipeline in Azure Data Factory you can invoke the runbook using a webhook

Related

Alternative to trigger Azure Functions or AppService based on a table row insert into Azure SQL MI

Is it possible to trigger Azure Functions or AppService webapp whenever an insert operation is performed against a table on Azure SQL MI?
if not, is there a way to trigger applications outside Azure SQL rather than using LogicApp? I want to avoid LogicApp because it requries using one more application, and it is still using polling.
Link below said it is not for Azure functions
https://feedback.azure.com/forums/355860-azure-functions/suggestions/16711846-sql-azure-trigger-support
Link below suggests using LogicApp.
Trigger Azure Function by inserting (adding) new row into table, SQL Server Database
Today, in Azure SQL, there is no such possibility. The closest option is to create a Timer Trigger Azure Function that checks if there has been any changes in the table you want to monitor (using Change Tracking, for example).
If you are using Azure SQL MI instead, you could create a SQLCLR procedure that calls an Azure Function via an HTTP request or, another option, via Azure Event Hubs or Azure Event Grid
There have been several feature requests for triggering Azure functions based on changes to at Azure SQL database. For example:
https://github.com/Azure/azure-functions-python-worker/issues/365
It seems that they are not prioritizing it, since it is possible to implement this functionality using logic apps.

Make REST call to API and save the result to Azure SQL every hour

I'm using this very useful SQLCLR script to make a REST call to an API and save the data on SQL Server on the fly.
I have created a stored procedure that withdraws new data every hour so my data are always updated.
I would like to have all this on Azure so I can then create a Power BI data visualization.
THE PROBLEM:
As soon as I try to transfer the database on Azure I receive this error:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Could not import package.
Warning SQL0: A project which specifies SQL Server 2019 or Azure SQL Database Managed Instance as the target platform may experience compatibility issues with Microsoft Azure SQL Database v12.
Error SQL72014: .Net SqlClient Data Provider: Msg 40517, Level 16, State 1, Line 4 Keyword or statement option 'unsafe' is not supported in this version of SQL Server.
Error SQL72045: Script execution error. The executed script:
CREATE ASSEMBLY [ClrHttpRequest]
AUTHORIZATION [dbo]
FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0103006D85475F0000000000000000E00022200B0130000026000000060000000000007E45000000200000006000000000001000200000000200000400000000000000060000000000000000A00000000200004C1E01000300608500001000001000000000100000100000000000001000000000000000000000002C4500004F00000000600000FC03000000000000000000000000000000000000008000000C000000F44300001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E7465787400000084250000002000000026000000020000000000000000000000000000200000602E72737263000000FC030000006000000004000000280000000000000000000000000000400000402E72656C6F6300000C000000008000000002000000
(Microsoft.SqlServer.Dac)
------------------------------
BUTTONS:
OK
------------------------------
This happens because Azure SQL has some feature stripped off like SQLCLR or SQL Server Agent (for some obvious security reason).
Is there any alternative to SQLCLR on Azure?
Is there any alternative to SQL Server Agent on Azure?
Basically: how to automate a REST call to an API every hour and save the result to SQL Server on Azure?
I do not think there is a straight forward replacement for SQL CLR. However, there are some Azure offerings that might be interesting.
I suppose an alternative is using a scheduled azure function that calls the API and store the result in the Azure SQL Database.
Do mind that if the process takes longer than 10 minutes you cannot use a consumption plan for the Azure Function, which is the most cost effective probably.
Depending on the scenario, Azure Data Factory can also provide a solution. You can create a pipeline that calls the API and copies the data to Sql Server as outlined here, based on a schedule trigger.
Even though Azure Functions is great, you could even solve this without much code using Azure Logic Apps, a scheduled trigger, the http request and the mssql connector.
https://azure.microsoft.com/de-de/services/logic-apps/

MS Azure PaaS Web App Service + Local Deployment

My application is running on Azure PaaS (BLOB Storage, Azure SQL, Web App)
One of my clients requires having the sql database and storage account to be on his premises.
What is the best topography you would recommend? is there a way to replicate the BLOB storage in real-time?
How can I assert high availability knowing that his SQL and his Storage are subject for failure?
Unfortunately there isn't a 1:1 on-premise equivalent of either Azure blobs or Azure web apps. Specifically for SQL DB, you can use SQL Server in it's place.
I hope this helps.
One of my clients requires having the sql database and storage account
to be on his premises.
SQL Database is easy. It is just replacing the connection string.
Storage is tricky. You might be able to modify local storage emulator, and allow access from outside, but I have never tried it.
Your application will be quite slow, since it has to access SQL and Storage from on-premise. My thought will be to host it on-premise where all resources are there.

Can I output to a VM running SQL Server from Azure Analytics job?

Generating output to a Azure SQL database is supported, but I was shocked when I found that the portal does not allow to specify a SQL Server database running on a VM. Is not this supported?
We need to store lots of data coming through the ASA jobs, and use SQL Jobs, that's why we were planning to use a SQL Server VM.
Thanks!
You cannot configure the SQL Database running on VM as an output to the ASA job.
However, Azure provides SQL services with 2 variants
Microsoft Azure SQL Database (Azure SQL Database) as PaaS
where lower stack is managed by Microsoft Azure and billed as pay-as-you-go model.
and
SQL Server in Azure Virtual Machine (VM) as IaaS where user owns the VM and make any changes, including licences for the SQL database.
the Microsoft Azure SQL Database provided as PaaS is configurable as
ASA output.
one idea might be to create and Event Hub output for the ASA and then consume it from there using any sort of application to write into an IaaS SQL DB. The application that consumes the data can also be hosted as a Web App as well.
Hope this helps.

Azure SQL procedure add in schedulers

I've got the Azure SQL procedure for migrating data from table A to table B. And I need to run this procedure at 15 min intervals.
I thought I could use Azure webjob for it, but I don't know how to call my azure sql procedure.
Are there any available schedulers in azure sql or how is it possible to make add Azure sql procedure to the Azure scheduler?
One option for scheduling Azure SQL Database stored procedures would be to leverage Azure Automation. There is a blog post which explains how to run TSQL with Azure Automation here. Azure Automation has a scheduler built in, however if it doesn't meet your needs, you could leverage Azure Scheduler to schedule the Automation Runbook instead.

Resources