I need a little help as this is driving me crazy and was not able to identify the root cause.
I've developed a program that uses and SQLExpress to store some data.
I've added a function to perform a backup of the DB via T-SQL:
var backupCommand = "BACKUP DATABASE @databaseName TO DISK = @backupFilePath WITH FORMAT, INIT, SKIP, NOREWIND, NOUNLOAD";
try
{
using (var conn = new SqlConnection(SQLServerSelectorService.ConnectionString))
{
using (var cmd = new SqlCommand(backupCommand, conn))
{
conn.Open();
cmd.Parameters.AddWithValue("@databaseName", conn.Database);
cmd.Parameters.AddWithValue("@backupFilePath", _destf);
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
The _destf is could be both in a new folder or in the user documents folder.
What is driving me mad is the fact I have a different behaviour on different machines even if, in theory, the setup is the same.
1) development machine -> works well
2) test machine -> always issuse - File system access error.
The setup of the test machine is:
a) clean setup of W10 Home or Pro
b) SQL Server Express setup with all default values
c) SQL Server Tools setup with default values
On the program works perfectly, SQL Server is accessed, data is read and wrote, everything fine BUT it does not backup.
The issue is there even if I launch the app as Administrator.
If I add to the folder the user SQLServer2005SQLBrowserUser$ the issue is still there.
As workaround I've discovered that in the Folder Security on the file system I add the group "Users" with basic modify, read, write permissions it works.
Can you help me understand what's going on? if/how to solve it?