C#C
C#3y ago
Populus

❔ Entity Framework - SqlException

Microsoft.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name is invalid.
)'

internal static async Task Initialize(WebScraperContext context)
        {
            context.Database.Migrate();
        }

using (var db = new WebScraperContext())
            {
                db.Database.EnsureCreated();
                db.SaveChanges();
            }

public class WebScraperContext : DbContext
        {
            public DbSet<WebPage> WebPages { get; set; }

            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                optionsBuilder.UseSqlServer(@"Server=(localdb)\\MSSQLLocalDB;Database=my_localnetwork;Trusted_Connection=True;");
            }
        }
Was this page helpful?