Sql-server – How to setup Database Permissions on SqlServer Express 2008

iispermissionssql server

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

Best Answer

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 ;)