Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm writing a backup program for our new server. I'm an administrator, and I'm learning a lot. The issue is that I can back up a file on the c:\ drive to the c:\ drive, but not for the drives on the SAN, like when I try to backup a file on the T drive (SAN) to the H drive (server). I tried using SetAttributes like
System.UnauthorizedAccessException: Access to the path denied[^]
but it basically gives the same error message to try setAttributes as I did when I tried to copy the file. This is a portion of my log:

12/30/2013 2:14:57 PM Successful backup of file C:\test\iceCreamCake_12_30_2013_1414P.docx
12/30/2013 2:14:57 PM exception during backupSystem.UnauthorizedAccessException: Access to the path 'T:\T Drive.vhd' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.SetAttributes(String path, FileAttributes fileAttributes)
   at Bak.BackItUp(String fromDrive, String toDrive) in C:\Users\michele\BackupProj\ServerBackup\ServerBackup\Backup.cs:line 36
12/30/2013 2:14:57 PM exception during backupSystem.UnauthorizedAccessException: Access to the path 'S:\SQL Database.vhd' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.SetAttributes(String path, FileAttributes fileAttributes)
   at Bak.BackItUp(String fromDrive, String toDrive) in C:\Users\michele\BackupProj\ServerBackup\ServerBackup\Backup.cs:line 36


Shouldn't I be able to run my program to do the backup if I'm logged on as Administrator?

Here's part of the code:

C#
try
{
    if (System.IO.File.Exists(fromDrive))
    {
        result = 4;
        if (System.IO.Directory.Exists(toDrive))
        {
            string oldFileName = Path.GetFileName(fromDrive); //file name only
            string sourcePath = Path.GetDirectoryName(fromDrive); //path only
            string newFileName = AppendFileNameWithDate(oldFileName); //file name with date added
            string destFile = System.IO.Path.Combine(toDrive, newFileName); //full path of final destination with new file name
            result = 3;

            System.IO.File.SetAttributes(fromDrive, FileAttributes.Normal);
            System.IO.File.Copy(fromDrive, destFile, true);  //copy backupFileName to toDrive, overwrite destination file if it already exists
            if (File.Exists(destFile))
            {
                Logging.Logging.Instance.Debug("Successful backup of file " + destFile);
                result = 2;
            }
            else
            {
                result = -2;
                Logging.Logging.Instance.Debug("Backup *failure of file " + destFile);
            }

        }
        else
        {
            Logging.Logging.Instance.Debug("to Drive does not exist: " + toDrive);
            result = -1;
        }
    }
    else
    {
        Logging.Logging.Instance.Debug("from Drive does not exist: " + fromDrive);
        result = -1;
    }
}
catch (Exception ex)
{
    Logging.Logging.Instance.Debug("exception during backup" + ex.ToString());
}


The directory strings are like this:

C#
string cDrive  = @"C:\backup\2013\iceCreamCake.docx";
string tDrive  =  @"T:\T Drive.vhd";
string sDrive  =  @"S:\SQL Database.vhd";

string cDriveToLocation = @"C:\test";
string tDriveToLocation = @"H:\";
string sDriveToLocation = @"E:\";
string vDriveToLocation = @"G:\";


The SAN is set up as SAS (not network share or iSCSI), so it is the same as a physically connected hard drive. We were able to open a command window and could xcopy the file on the t-drive to the h-drive, so it's just the code that can't do the copy/recognize the path. I tried changing the filename to @"T:\T_Drive.vhd", and also tried changing the FileAttributes line to: System.IO.File.SetAttributes(fromDrive, FileAttributes.System); It still gives the same error message. It looks like it can't access the path to the file.

I looked at these links but I'm having newbie issues too I think:
http://stackoverflow.com/questions/1267085/vista-uac-trouble-mapping-network-drives[^]

http://stackoverflow.com/questions/8821410/system-unauthorizedaccessexception-access-to-the-path-denied?lq=1[^]

http://stackoverflow.com/questions/6402536/access-to-the-path-xxx-is-denied?rq=1[^]

Thanks,
Michele
Posted
Updated 7-Jan-14 4:17am
v4

1 solution

I'm going to take a guess and say you might need to use the UNC path vs. the mapped path.

Here instead of Z:\PlaceIWantToAccess we often need to use \\TheServer\PlaceIWantToAccess
 
Share this answer
 
Comments
MichCl 7-Jan-14 10:12am    
By \\TheServer do you mean the IP address or what?
bowlturner 7-Jan-14 10:20am    
no while the IP can work I wouldn't use it. Use the name of the server and the share path. Look up in the properties of the share at the path. \\ServerName\Share
MichCl 7-Jan-14 14:16pm    
We don't have our server set up as a share. I'm not sure how to access it with server name \\USA0261xxxxx without the drive letter.
bowlturner 7-Jan-14 14:24pm    
if it's mapped and accessible, it is shared. Right click on the T: drive and go to properties. In Windows 7 there is a DFS tab. it will show you the UNC path, you might also ask the server administrator for it as well.
MichCl 7-Jan-14 14:43pm    
I am the administrator, but we are all learning. When I go to T:\ properties, it says not shared. I can go to Advanced Sharing and give it a share name, but shouldn't I already have access since I'm logged onto the server directly? Plus I can open a command window and cd t:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900