I have the following code to create a back-up of the database.
public void CreateBackup()
{
if (_database.Database.CanConnect() == false)
{
throw new Exception("No connection to the Database could be established.");
}
_database.Database.ExecuteSqlCommand($@"BACKUP DATABASE {_databaseSettings.DestinationSettings.SSMSDatabaseName} TO DISK='{_databaseSettings.BackupSettings.BackupFilePath}{Path.DirectorySeparatorChar}{_databaseSettings.DestinationSettings.SSMSDatabaseName}_{DateTime.Now.ToString("dd-MMMM-yyyy HH_mm")}.bak'");
}
The ExecuteSqlCommand will be converted into
BACKUP DATABASE databasename TO DISK='D:\backup\databasename_03-november-2021 15_52.bak'
When I run this SQL command via the SSMS query prompt, it will start creating the back-up with no issue. When I run the above code, which should do essentially the same, it will take the same amount of time as if it is creating a back-up but will not actually create the back-up. I have attempted to run this application on the same computer as the one where the database is hosted. It did not make a difference. I receive no errors from the application.
Could anyone help me make sense of this?
Resources that I've read and checked: https://stackoverflow.com/a/9835597/12175949