Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can create a database easily in Sql Server Full edition but not in Sql Server Express and the reason seems to be 'right to access' the specified folder or in other words, that folder seems to be invisible to Sql Server Express services.
For example, CREATE DATABASE MYDB
ON PRIMARY (NAME = 'Chan doi vl', FILENAME = 'd:\MyDb.mdf')
will not be successfully executed with an error telling something like '...operating system error 5 (Access is denied)...'
I have googled for the solution for hours and I guess I have to change something to make sql server express services have right to access but I can't find out how to do and if that is possibly achieved, can we use code (sql statement) to do that instead of using Enterprise Manager?
Please help me out!
All your helps would be high appreciated!
Thank you very much!
Posted
Updated 12-Dec-11 4:23am
v3
Comments
[no name] 12-Dec-11 8:07am    
Any mods please edit my question tag to 'database,c#' . I can't do that and also can't understand why.
Thank you!

Simple: it's a root folder. Vista and above severely restrict the right to create files in the root folder. Change to a subfolder and you should have no such problems.
 
Share this answer
 
Comments
[no name] 12-Dec-11 12:20pm    
Thank you! But I have tried with some subfolders such as C:\Documents and Settings\Administrator\Desktop , C:\Program files ...
and there is nothing different except that error.
Thank you very much!
[no name] 12-Dec-11 12:37pm    
The only folder that I can create my database in is the one containing system databases like master, model ... (it is MSSQL.1 or MSSQL.2 ... but I don't remember its name exactly).
I forgot to try creating new database using Enterprise Manager but it seems that all tries with using sql statement to create new database are failed (except the case I mentioned above).
I found my own solution, in fact there is no difference about access right between Express Edition and others. My Sql Server Express Services couldn't access the local physical disks because of their limited-privilege accounts which are type of 'Network service'. I changed the account type to 'Local system' and it works well. You simply only need to right-click on server name on the left panel in the manager window, select 'Properties', a new dialogue appears then you select 'Log on' tab and you can choose the expected type of account for the services.
 
Share this answer
 
v2
Comments
DaveAuld 18-Dec-11 4:47am    
These accounts are used for a reason, changing the default account from Network Service to Local Service just increases the attack service for a vulnerability to reek havoc on your system. If you are finding you need to change the account you are using, then you have incorrectly setup a basic install, and should reconsider what you have done.

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