I have an application which will create a SQL database(using CREATE DATABASE) and the database files are supposed to be placed in c:\program files\myApp\data\myDatabase.mdf
However, when I try to do so, I get the following error:
System.ApplicationException: System.Data.SqlClient.SqlException: CREATE DATABASE failed. Some file names listed could not be created. Check related errors.CREATE FILE encountered operating system error 5(Access Denied) while attempting to open or create the physical file 'C:\Program Files\myApp\data\myDatabase.mdf'.
My window login already have administrator role.
The problem can be solved if I manually add full access right to my login in window exploder. However, how can I do this programmatically Or what is the proper way to create database located under my application folder

Database create error due to folder access right.
Pat O
This directory works:
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
Anything else like
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\OtherFolder
generated the above mentioned error. I don't remember granting any permissions at installation, so I suppose I have the default which only takes the ...\Data folder.
Mike Turner
Are you referring to the SQL Server Express (SSE) installation or to your application installation
In the first case, I don't think there is a way to grant access at installation time, unless the data folder is the same as your app data folder. For the second case, you can determine the SSE service account and grant it permissions to your folder at the time you install your application.
Thanks
Laurentiu
Timbob
If I would like to include SQL Server Express as a pre-requirite of my application, can I grant my app folder write access right of the SQL Server service account during installation
Thanks again.
Bleah
Jurney
thanks,
mark
A.F.B
sultan000
To find out the service account, execute Start->Run->services.msc and then look for the SQL Server service entry; you should find in it the name of the service account.
Thanks
Laurentiu