A
A
akass2016-03-02 21:30:42
Database
akass, 2016-03-02 21:30:42

How to publish ASP.NET with EF CodeFirst?

For the first time I am publishing a project on ASP and I am amazed at what a hemorrhoid it is, I can’t do it for the second day.
I do web deploy and when registering a user, it throws out
CREATE DATABASE permission denied in database 'master'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.
I thought that all actions with the database go by login / password, which are in the connection string.
Can someone explain how this whole ecosystem works and how to start a simple project from a database to EF?
Migrations are enabled.
ASP Identity is used for registration

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Kulakov, 2016-03-03
@akass

And what exactly is the problem?
case 1: the database server belongs to the hosting. accordingly, he closed access to creating databases out of harm's way, which is actually understandable and reasonable, otherwise each Vasya will create and delete databases there. In this case, the database probably already exists and you should not drop it, for sure EF knows how to work with an existing database and not create it again.
case 2: the database server is your physical or virtual server for which you are fully responsible. well so create the user who will be able to create databases and create through it.
case 3 : everything is the same as in the second case, except that you are not a Database Server Administrator. well, pull the administrator to give rights or at least turn the situation into case 1 - that is, he guarantees you a database and you are already creating tables and other necessary crap.

D
Dasha Tsiklauri, 2016-03-02
@dasha_programmist

something like this when starting the application, you need to check the rights in the DBMS for the login / password

Log_app.Info("Checking database...");
            using (var ctx = new ApplicationDbCtx())
            {
                if (!ctx.Database.Exists() || !ctx.Database.CompatibleWithModel(false))
                {
                    try
                    {
                        Log_app.Info("updating Database ...");
                        Database.SetInitializer<ApplicationDbCtx>(new MigrateDatabaseToLatestVersion<ApplicationDbCtx, MyApplication.Migrations.Configuration>());
                        ctx.Database.Initialize(true);
                    }
                    catch (Exception ex)
                    {
                        Log_app.Error(ex);
                    }
                }
            }
            Log_app.Info("checking Database completed!");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question