C#C
C#4y ago
Sal

EF Migration error

hi,
I am getting an error message, and I am guessing comes from the connection string Initial catalog that I named after the name of the project from lack of info in all the sources I looked into. i followed the documentation and added App.config with a connection string and also read the page for ConfigurationManager but no one seems to tell how to name the "initial catalog" . i am following the dotNet tutorial on EF ,if anybody could help me out i really appreciate, thanks

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
  optionsBuilder.UseSqlServer(
    ConfigurationManager.ConnectionStrings["myappnameDatabase"].ConnectionString);//line 19   
}

App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
        <add name="myappnameDatabase"
             connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=myappname;Integrated Security=True;" />
    </connectionStrings>
</configuration>

on package console
PM> Add-Migration InitialCreate
Build started...
Build succeeded.
System.NullReferenceException: Object reference not set to an instance of an object.
   at myappname.Data.myappnameContext.OnConfiguring(DbContextOptionsBuilder optionsBuilder) (...) :line 19
Was this page helpful?