Hello,
I am currently working on this tutorial to learn ASP.net https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/create_the_data_access_layer but the stuff with my database is not working. I.e. when I run the website the database is not created automatically. Instead of creating a default database as described in the tutorial I would like to use my local SQL Server 2017. So what I did to do this is use another connection string and refer to it from the context class:
public class ProductContext : DbContext
{
public ProductContext() : base("name=WingtipToys")
{
}
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
}
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WingtipToys-20171201071611.mdf;Initial Catalog=aspnet-WingtipToys-20171201071611;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="WingtipToys"
connectionString="Data Source=(local);Initial Catalog=wingtiptoys;Integrated Security=sspi"
providerName="System.Data.SqlClient" />
</connectionStrings>
But for some reason this is not working. I also tried if I can connect programatically and it worked fine.
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = "Data Source=(local);Initial Catalog=wingtiptoys;Integrated Security=sspi";
sqlConnection.Open();
I am using sspi as I want to do Windows Authentification.
So I don't understand why the Entity Framework isn't doing what it is supposed to do. Unfortunately I also don't see any information in the output window of Visual Studio so I have no idea what's going on. When I look into the profile window on my SQL Server Management Studio I see that nothing is done.
Has anyone an idea what else I can try?
Best regards
Thomas