code-first

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


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"/>

Solution

  • Permission denied is a security so you need to add a "User" permission..

    1. Right click you database(which is .mdf file) and then properties
    2. Go to security tab
    3. Click Continue button
    4. Click Add button
    5. Click Advance button
    6. Another window will show, then you click the "Find Now" button on the right side.
    7. On the fields below, go to the bottom most and click the "Users". Click OK.
    8. Click the permission "Users" that you have been created, then Check the full control checkbox.

    There you go. You have now permission to your database.

    Note: The connection-string in the above questions is using SQL-server authentication. So, Before taking the above step, You have to login using windows-authentication first, and then you have to give permission to the user who is using sql-server authentication. Permission like "dbcreator".

    if you login with SQL server authentication and trying to give permission to the user you logged in. it shows, permission denied error.