Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using a code-first approach of using the Entity Framework. When I first run the application it will try to create the database matching my MVC models.

However, it doesn't have permission to create it I think. I get the following error:

CREATE DATABASE permission denied in database 'master'.

What user is trying to access the SqlServer and how can I add it's permissions to let it work?

This is the connectionstring I'm using (which should be right...)

<add name="ContextDb"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=ContextDb"
     providerName="System.Data.SqlClient"/>

Cheers

share|improve this question
add comment

2 Answers

General tip: DO NOT DO THAT.

Database creation - outside very simplistic scenarios - is an administrative act and should not happen by a user. In fact, you should not expect to be able to do any DDL at all - no table creation etcl. Nothing.

Basic security 101 for beginners says that creation and maintenance of databases are not done by non-trusted users but by administrators.

That is why you normally do that in a setup and / or in a tool you provide that the administrator can run.

Only extremely simplistic scenarios can get away, and only with a local express database ONLY. But even then you trust the users a lot - I really hope this is not high level stuff. Without any reconfiguratoin on the SQL Express side, this means the user has to be administrator ;)

share|improve this answer
add comment

When you use the "Integrated Security=SSPI" in your connection string that means that the connection to SQL will be made using the Windows credentials of the user running the executable. The web site connectionstrings.com is a good reference for building connection strings.

share|improve this answer
    
Yes I know, but I'd like to know how I can configure SQLExpress to accept my windows credentials :P Thanks for that website though :D –  Timo Willemsen Oct 6 '11 at 12:48
    
That is how you have it configured now, you just need to assign the database creation rights first. If the user running the installer is in the local administrators group then the user would have sysadmin rights on the SQLEXPRESS instance and be able to create the database, but otherwise you are going to come in with the rights associated with guest. SQL creates local machine groups (SQLServerMSSQLUser$<COMPUTERNAME>$SQLEXPRESS) to assign sysadmin rights, you could also add the user into that group before trying to create the database. –  Jason Cumberland Oct 6 '11 at 18:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.