0

I'm trying to deploy my first MVC website (using arvixe as my host) and I'm having problems with the database. When I develop on my local and I change anything on my Models (mapped on my DbContext) it wipes out my database and creates a new one (if it exists) or just completely create a database for my entities.

With that said, my problem is when I deploy it, my project that has all the controllers gets deployed and I can access my landing page but once I try to login (which triggers the creating of a database on my local) it will just give me an error and wouldn't try to create the database.

Not really sure what I'm missing on the steps, should I be creating the database at least without the records first?

3 Answers 3

0

This sounds like a permissions problem. The account you are running on your server most likely does not have permissions to DROP/CREATE tables.

When deploying to production / hosted server I generally do not rely on EF to create my schema. I copy my CREATE tabel scripts from my DEV enviorment to PRODUCTION and make sure my DBCONTEXT intialisation code is set NOT TO make any changes.

Sign up to request clarification or add additional context in comments.

2 Comments

this seems like the way to go, i was just reading this > stackoverflow.com/a/10760985/639713 and apparently i have to generate scripts to run? is that right? i tried doing that and it has been 15 min and no table was created..not sure what's wrong.. also, what do u mean by "make sure my DBCONTEXT intialisation code is set NOT TO make any changes." ?
if you have DbDatabase.SetInitializer<MyDBContext>(new DropCreateDatabaseIfModelChanges<MyDBContext>()); you may need to change DropCreateDatabaseIfModelChanges to some other setting
0

Try This:

using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Data.Entity.ModelConfiguration.Conventions;
public class YourDbContext: DbContext
{
    public YourDbContext()
        : base("name = YourConnection")
    {
        Database.SetInitializer<YourDbContext>(new MigrateDatabaseToLatestVersion<YourDbContext, YourMigrationsConfiguration>());
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        //Your Building Rules
    }

    #region DbSets
    public DbSet<YourTable> YourTables { get; set; }
    #endregion
}

public class YourMigrationsConfiguration : DbMigrationsConfiguration<YourDbContext>
{
    public YourMigrationsConfiguration()
        : base()
    {
        AutomaticMigrationsEnabled = true;
        AutomaticMigrationDataLossAllowed = true;
    }

    protected override void Seed(YourDbContext context)
    {
        /*sql script*/
    }
}

Comments

0

So apparently the only way I can do the same thing that my App does in my local to my host is to have sysadmin permissions/account to drop the dbase. which is not happening...ever.. So I decided to just generate a script and run it remotely. I'm not sure how it will affect my database once i start doing alterations on tables and maintenance on the data. wish me luck.

oh btw, here's my source for the script

https://stackoverflow.com/a/10760985/639713

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.