CREATE DATABASE permission denied in database 'master' (EF code-first)

Mohammad picture Mohammad · Jun 27, 2012 · Viewed 226.7k times · Source

I use code-first in my project and deploy on host but I get error

CREATE DATABASE permission denied in database 'master'.

This is my connection string:

<add name="DefaultConnection" 
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-test-2012615153521;Integrated Security=False" 
     providerName="System.Data.SqlClient;User ID=test;Password=test"/>

Answer

Willy David Jr picture Willy David Jr · Jun 11, 2017

I had the same problem. This what worked for me:

  1. Go to SQL Server Management Studio and run it as Administrator.
  2. Choose Security -> Then Logins
  3. Choose the usernames or whatever users that will access your database under the Logins and Double Click it.
  4. Give them a Server Roles that will give them credentials to create database. On my case, public was already checked so I checked dbcreator and sysadmin.
  5. Run update-database again on Package Manager Console. Database should now successfully created.

Here is an image so that you can get the bigger picture, I blurred my credentials of course:enter image description here