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?The account that sql runs as needs to have the security privledge to access the directory or file.
thanks,
mark|||Sorry that I am using SQL authenication and provide the sa password in the connection string. How can I create database in my application folder?|||As Mark pointed out, you will need to grant write access to that directory to the SQL Server service account. The error is not related to the permissions of the account that you use to connect to SQL Server when you execute the CREATE DATABASE statement.
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|||I see. Thank you very much.
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.|||
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
No comments:
Post a Comment