Backup database from code: Access denied on user specific directories

R

Robin

I want to backup a sql express database from my windows forms C# code. I can
do this by running a sql command "BACKUP DATABASE TO..." (or using SMO) and
I can save the backup file to any subdirectories of C:. The problem I have
is that I want the user to be able to save the backup file to any location,
including C:\...documents and settingsm\my documents...

However, the file access for these directories (user specific) are more
limited and the BACKUP DATABASE command fails due to Access Denied.

Should I mess with the ACL to grant NETWORK SERVICE read/write permissions
on the directory they want to save to? I am not very comfortable doing this
as I don't like the idea of changing the ACL security on someone's system.

The simplest solution is for me to restrict where they can save the backup
file (to subdirectory of C:\), but if there are any other solutions, I'd
like to hear them.

Thanks.
 
L

Linda Liu [MSFT]

Hi Robin,

Could you tell me what the OS is on your machine?

In my opinion, it is not a good idea to grant NETWORK SERVICE read/write
permissions on the directory the user wants to save to, because it will
break the access security.

I think the simplest way is to use the try...catch structure to catch the
exception when the user attemps to save the file to a directory that he
doesn't has the corresponding permission.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Robin

Development is being done on Windows XP. Application is recommended to run
on Windows XP also.
 
L

Linda Liu [MSFT]

Hi Robin,

Thank you for your response.

Then how about my suggestion? Is it appropriate to your practice?

If you need our further assistance, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top