@J L, Welcome to Microsoft Q&A, based on the Microsoft Learning Example, we need to use database name instead of mdf file name to back up database.
Here is a code example you could refer to.
private void button1_Click(object sender, EventArgs e)
{
string connstr = "connstr";
SqlConnection connection = new SqlConnection(connstr);
connection.Open();
string path = @"C:\example\Test.bak";
string sql =string.Format("BACKUP DATABASE Test To Disk='{0}' WITH STATS",path);
SqlCommand command = new SqlCommand(sql, connection);
command.ExecuteNonQuery();
Console.WriteLine("11");
}
Based on my test, it could generate the bak file in the correct path:
Hope my code could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.