There is a rich API to manage Azure instances, servers, and security policies at az sql reference and Azure CLI reference commands for Azure SQL . But how can we simply connect to an existing subscription [or at least to a connection string] and run basic sql commands? I have not found an alternate API or any methods within these existing api’s to do so. Can one or more of the admin-focused methods be repurposed to run general queries / run general DML commands?
The preference would be to use an existing Azure-Subscription as the basis of the connectivity. In that way we do not need to access KeyVault for the server passwords [and URI’s etc].
2
Answers
I'm trying out Sqlcmd and will embed it in a Bash@3 task. Note it does work from macOS and Linux
ubuntu:
Notice there are no passwords being shoved around here: the -G denotes to use ActiveDirectory behind the scenes with the logged-in user's credentials. This should translate as well to Azure
That brings up the T-sql prompt. Then the insert statement we need can be invoked.
Update On ADO the ActiveDirectory login is not found automatically. I will need to update this approach with the mechanisms to enable it.
The specific error message:
Consider using PowerShell Core and Invoke-Sqlcmd. It supports cross-platform: Invoke-Sqlcmd is Now Available Supporting Cross-Platform. Check examples of connecting to Azure SQL: Connect to Azure SQL Database. You may share query results through the logging commands: About task.setvariable
Setup PowerShell@2 to use PowerShell Core: