EF Code First CREATE DATABASE permission denied in database 'master'
Asked Answered
B

4

2

I used code first for create and update database. My update-database commands in package manager worked until yesterday. But today it is not working and has this error: CREATE DATABASE permission denied in database 'master'. I do not any changes on connection string and other config. So I try to Update-database to another project on my system and my windows and I can recreate and update this database without any problem. Can you help me for fix this error?

This is my connection string for project that has problem:

<add name="Default" connectionString="Server=.\sqlexpress; Database=test1; User Id=sa; Password=123456" providerName="System.Data.SqlClient" />

this is my connection string for project that have not problem:

<add name="Default" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=test2;user id=sa;password=123456" providerName="System.Data.SqlClient" />
Bilek answered 11/8, 2016 at 8:34 Comment(0)
B
3

I found my solution.

I have 4 project in the solution. but when I try to update-database, the web project does not set as start up project. so I set this project to start up project and I can update-database.

Bilek answered 13/8, 2016 at 3:55 Comment(0)
N
2

To create the database:

Open the Security folder, then open the Logins folder and select the user account under which you want to create the database. Open the account's Properties, select the Server Roles tab and then select the dbcreator checkbox (sysadmin works even better). You can also try to create the database while logged in under the standard administrator account, sa.

Noway answered 11/8, 2016 at 8:38 Comment(2)
Hi Dear. Thank you for your answer. but you can see, I use 'sa' user and it has all of permission to create database. also I use this user for another project and it has not error!!!Bilek
@masoudnoursaid so I think your problem has been solved.Noway
E
0

To create databases on a database server, you must authority. Hence, the username you are using must have permission to create database on the server. You Database administrator (DBA) will grant you the permissions to do so.

In development environment, you can use sa account, which has all the permission to do anything on the server. Even better, if you use localdb for development as it is much light-weight and developer friendly.

So, Basically you need permission in your case to create database in your server. Hope, this helps you someway.

Eternal answered 11/8, 2016 at 8:44 Comment(1)
Hi Dear. Thank you for your answer. but you can see, I use 'sa' user and it has all of permission to create database. also I use this user for another project and it has not error!!!Bilek
I
0

You can Use SA Or you can add it (youraccount) to dbcreator or sysadmin roles.

sp_dropsrvrolemember 'Youraccount','sysadmin'

or

sp_dropsrvrolemember 'youraccoount','dbcreator'
Irrigation answered 11/8, 2016 at 8:57 Comment(1)
Hi Dear. Thank you for your answer. but you can see, I use 'sa' user and it has all of permission to create database. also I use this user for another project and it has not error!!!Bilek

© 2022 - 2024 — McMap. All rights reserved.