1

I followed a tutorial on pluralsight for ASP .NET 5 and EF 7 using Code First DB. This is the connection string :

"WorldContextConnection": "Server=CVU-OCTAVIANE\\SQLEXPRESS;Database=TheWorldDB;Trusted_Connection=true;"

I added the initial migration (which worked fine) and then I tried to use a EF 7 feature to create the DB automatically: I created a Context type class where I used Database.EnsureCreated() to create the DB on the first run. This is the context class:

public class WorldContext : DbContext
{
    public WorldContext()
    {
        Database.EnsureCreated();
    }

    public DbSet<Trip> Trips { get; set; }
    public DbSet<Stop> Stops { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        var connString = Startup.Configuration["Data:WorldContextConnection"];

        optionsBuilder.UseSqlServer(connString);
        base.OnConfiguring(optionsBuilder);
    }
}

When I ran the project "A severe error occurred on the current command"

Thanks

2
  • That's a generic error. You may debug that method to find the inner exception. Just add a try catch and on the catch put a Debugger.Launch(); and the exception occurs it will ask to launch visual studio and you accept it and then you are able to see the full exception. Commented Jan 27, 2016 at 10:31
  • @Leandro Soares - I ran the project in Debug mode, but the Inner Exception is null - I have no other info about the error. Commented Jan 27, 2016 at 10:43

2 Answers 2

1

I had the same problem and seem to have resolved it.

I'm not sure if all of the below is required, but are the steps I took

  • Deleted all migration .cs files under the Migrations folder
  • Deleted TheWorldDB from SQL Server Object Explorer
  • Closed Visual Studio
  • Upgraded ASP.NET 5 to RC1 Final at get.asp.net
  • Opened Visual Studio
  • Updated global.json to use "version": "1.0.0-rc1-final"
  • Updated project.json to use latest "dependencies"
    • "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    • "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    • "Microsoft.AspNet.Mvc.Abstractions": "6.0.0-rc1-final",
    • "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    • "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    • "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    • "Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
    • "EntityFramework.Core": "7.0.0-rc1-final",
    • "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    • "EntityFramework.Commands": "7.0.0-rc1-final"
  • Ran dnvm install to get "1.0.0-rc1-final" and switched to it
  • Recreated migration with dnx ef migrations add InitialDatabase
  • Executed project and it worked
Sign up to request clarification or add additional context in comments.

Comments

0

Actually I had the same problem of yours, and I took a few steps less.

  • I removed the Migration folder
  • I updated my global.json to the default version of sdk that I'm using, (check using "dnvm list") which in my case was "update2".
  • Deleted the TheWorlDb from my SQL instance.
  • After that, I just generated again the migration of InitialDatabase
  • Clear, Build and Rebuild the solution.

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.