We have a windows on-premise scheduled task that we need to migrate to Azure Paas.
The scope of the task is to restore a clean version of the same database daily to improve site's performance.
The task action is to run a batch file, with the below script.
SQLCMD -E -S server-name -Q "use master; alter database myDatabase set
single_user with rollback immediate; alter database myDatabase set
multi_user; RESTORE DATABASE myDatabase FROM DISK='C:\Dir\myDatabase.bak';
USE myDatabase; CREATE USER myUser FOR LOGIN myUser; USE myDatabase; ALTER
ROLE db_owner ADD MEMBER myUser"
The requirement is to implement a similar functionality by creating an Azure C# WebJob project via Visual Studio and publish it as an Azure WebJob.
Only the schema of the database should remain, no data or logs.
using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["AzureDBConnString"]))
{
connection.Open();
var queryString_RestoreMyDatabase = @"?????"; // what to add here?
using (SqlCommand cmd_RestoreMyDatabase = new SqlCommand(queryString_RestoreMyDatabase, connection))
{
cmd_RestoreMyDatabase.ExecuteNonQuery();
}
}
Is the above possible? What SQL commands can we use for queryString_RestoreMyDatabase
to achieve as per title of this post?