I'm not quite sure what you mean by:
I'm writing a program to create a backup of a database and I need to
be able to access the backup file in my program afterwards.
If you mean the Client will need to Restore the Backup you can actually do that pragmatically.
Backup Example:
using (SqlConnection defaultSqlConnection = new SqlConnection("Insert Connection String Here"))
{
string backupDb = "BACKUP DATABASE [DatabaseName] TO DISK = 'C:\\Users\\Account\\Desktop\\Database Name.bak'";
using (SqlCommand backupCommand = new SqlCommand(backupDb, defaultSqlConnection))
{
defaultSqlConnection.Open();
backupCommand.ExecuteNonQuery();
}
}
As you can see our application is simple using SQL to create a backup. The Restore Process is a bit more complex due to variation in methodologies to Restore. You can find the Syntax here. If you couple my original example, just with Restore syntax it should work without a problem.
Obviously you may encounter such issues:
- Multiple Users Using Database
- Permissions to Read / Write to Network Share.
You'll also want to ensure you have good Exception Handling and Test against several aspects to ensure the task is done correctly.
Hopefully that points you in the right direction, I believe CodePlex had a utility to accomplish a lot of MSSQL functions such as: Verify, Restore, Backup, and Create.