Azure SQL Failover through T-SQL - sql-server

I am conducting some tests, therefore I have two instances each in a specific region, the database has been configured with a geo-replica and added to a failover group.
While trying to trigger a failover through SQL commands, it looks like it doesn't want to work, but when I am going and logging into the azure portal, and selecting the instance then to the failover group, I can trigger a failover and also a forced failover , both of them working just fine, I was wondering how would this work from a SQL perspective?
To be noted the ALTER DATABASE [DB-NAME] FAILOVER; or ALTER AVAILABILITY GROUP [AGNAME] Failover; doesn't work.
Anyone experiencing similar issues?

Azure Failover doesn't support T-SQL approach.
Auto-failover groups can be managed programmatically using Azure
PowerShell, Azure CLI, and REST API.
To triggers failover of a failover group to the secondary server, use Switch-AzSqlDatabaseFailoverGroup Powershell command.
The above command swaps the roles of the servers in a Failover Group and switches all secondary databases to the primary role. All new TDS sessions are automatically re-routed to the secondary server after the DNS client cache is refreshed. When the original primary server is back online, all formerly primary databases in it will switch to the secondary role. The Failover Group's secondary server must be used to execute this command.
Refer Switch-AzSqlDatabaseFailoverGroup to know more.

Related

Extract data from one Azure SQL DB, transform and load into another Azure SQL DB

We have two Azure PaaS SQL Servers, one in our production resource group and another in our QA resource group.
I'm looking for the best way to 'copy' the data from an Azure SQL DB in the production resource group to an Azure SQL DB in the QA resource group. As part of this process the data must undergo some simple transformations to anonymise the data before it lands in the QA DB.
We have deletion locks in place on the resource groups so deleting and recreating databases is an option I'd rather avoid.
The 'copying' can take place on a weekly schedule and it would be acceptable to drop any existing data in the target Azure SQL DB each time the process is run.
What are the most suitable options in Azure to accomplish this?
Go with Azure Data Factory. You can use it for pretty much anything that SSIS was used for onsite, and more.

Make Azure SQL database offline in a failover group

Any idea how I can turn off/bring down primary Azure SQL database / SQL Server in fail over group to replicate an actual scenario like a data center is down? I tried renaming but doesn't work. All I am trying to do is take one of the Azure SQL databases offline in the failover group. Any ideas how it can be done please?
You can use a forced failover which may result in data loss same as a server down or datacenter down scenario. Note that is not the same as a manual or friendly failover using the portal, on which case there is no danger of data loss.
You can use REST API to generate a a forced failover as explained on this documentation.

Is it posible to use SQL Server Session Context with Azure elastic queries

I want to know if it's posible to share SQL Server SESSION CONTEXT variables between different Azure Sql databases using Elastic Queries.
I searched in official documentation but i can't found any information about this feature is available or not.
SESSION CONTEXT exists locally to a single server instance in SQL Server. (It's tied to a session). SQL Azure is built using SQL Server but there are some parts of the mapping that are opaque to customers (they can change based on circumstances such as what Edition you use or what version of the internal software we are using to deliver the service).
Elastic Queries is a feature to let you query from one database (source) to one or more other databases (target(s)). In such a model, you have a SQL Server session to the source database, and the elastic query has a separate connection/session to each other database being touched.
I think the question you are asking is "can I set the session context on the source connection/session and have it flow through to all the target connections when running queries there?" (That's my best guess - let me know if it is different). The answer today is "no" - the session variables do not flow from source to target as part of the elastic query. Also, since today elastic query is read-only, you can't use elastic query to set the session context individually on each target database connection/session as part of the operation.
In the future, we'll consider whether there is something like this we can do, but right now we don't have a committed timeline for something like this.
I hope this explains how things work a bit under the convers.
Sincerely,
Conor Cunningham
Architect, SQL

How to get notification from Azure Sql database on insert

I need to get a notification or call a webservice whenever a row is inserted into a specific table in my Azure Sql Database. I have been searching the web for a good solution, but i haven't found any.
I tried to call a web app service in Azure - but this is not allowed from Azure Sql Databases.
I looked at the Azure logic apps, but the SQL Server Connector has been removed.
How do I get notificated when a row is put in?
Although this is not natively supported in SQL Azure, there are a few different options you can consider.
1) Modify the calling code to insert a row into the table and write a message to Azure storage queue. You can have a separate process which drains the message from the queue and invokes the web service so that these actions are loosely coupled.
2) Enable change tracking on the specific table so that your app can discover the latest changes (i.e. inserts) to the table. This feature is well documented if you search the Azure SQL docs.

SQL Azure data replication between two Azure subscriptions

Since I initially created an Azure SQL Server database while building an app for a client, they have changed Azure subscriptions. The client wants the database migrated to a new account and eventually deprecate use on the old account when we are done with the new version of the app. In the meantime, they want any updates from the old database duplicated into the new database.
My question is, is there a way to update two databases, one a copy of the other, at the same time on separate Azure accounts?
I've read into active geo-replication but that looks like it can only be done between two databases in the same Azure subscription.
Thanks for the help.
Active geo-replication indeed is only possible inside a subscription, if you are using Azure SQL that wouldn't be possible with it. You could possibly use some kind of replication using on Premise SQL, but that would be pretty hacky. You would want to work with Azure SQL Data Sync.
If you are using a VM with the SQL Server you could create AlwaysOn databases for that purpose.
But if the question is: My question is, is there a way to update two databases, one a copy of the other, at the same time on separate Azure accounts?. You could probably code your application in such a way to write to 2 databases, but again, you would also need to keep track of operations

Resources