2

I'm facing some troubles with my EF Model.

History: When my app was released in production a few years ago, my EF model was created via the Model First (edmx) technique. I works well on my production server with my SQL SERVER db.

Now I'm doing some improvements on my app, and I decided to leave the Model First technique to go on the Code first technique. It's working great on my localhost, but when I release my new app version on my production server and when my app tries to use the model I got this message:

CREATE DATABASE permission denied in database 'master'.

But I don't get it... My database still exists on my production server (since several years). Why does EF would like to create something? What can be wrong?

Thanks in advance for your answers.

EDIT:

Summary:

  • For the same database on the same server
  • For the same connectionstring
  • For the same EF version (6)
  • App with Model First works without problem
  • App with Code First throw exception CREATE DATABASE permission denied in database 'master'.

BUT the database already exists. Why this error? Why does the code first version tries to create a database?

Yoann B
  • 123
  • 2
  • 12
  • Possible duplicate of [CREATE DATABASE permission denied in database 'master' (EF code-first)](http://stackoverflow.com/questions/11231934/create-database-permission-denied-in-database-master-ef-code-first) – Ivan Starostin Dec 11 '16 at 15:50
  • Nope. My problem is different: that works in Model First but not in Code First. – Yoann B Dec 11 '16 at 16:17
  • It's the same problem. In the end, database creation is SQL. Doesn't matter where the SQL comes from. – Gert Arnold Dec 11 '16 at 20:05
  • It's not the same problem. Notice that my database already exists, so why does EF would like to create it? And notice that it works with a Model First EF Model on the same server, same database and same user. – Yoann B Dec 12 '16 at 07:29
  • Did you check your connection string as stated under the link? – Ivan Starostin Dec 12 '16 at 07:49
  • I use the same connectionstring for the model first and code first versions – Yoann B Dec 12 '16 at 09:18
  • Well, the app thinks it should create the database, so the connection string points to a non-existing (or inaccessible) database. – Gert Arnold Dec 12 '16 at 13:42

2 Answers2

0

Check this

https://stackoverflow.com/a/19198471/8186328

Be sure that your connection string name is the same that the base constructor of your dbContext

dlogon
  • 71
  • 1
  • 5
  • Hi dlogon, the OP indicated that this question was different than their question (re: the comments). Is there something else that you can add to differentiate your answer from the answer linked to? – Brydenr Dec 17 '19 at 18:27
0

It doesn't see the target database and so it's trying to create it, even though (to you) it may be there.

When this happened to me, I realized the connection string was wrong. There are two places to double-check this:

  1. The connection string name in your model class (typically in the constructor).
  2. The corresponding connection string, i.e., server and database name, in the .config file.
Tawab Wakil
  • 1,737
  • 18
  • 33