如果在ASP.NET Core 6应用程序中使用命名连接字符串并遇到了该问题,可以使用以下步骤解决:
{ "ConnectionStrings": { "MyConnection": "Data Source=myserver;Initial Catalog=mydatabase;Integrated Security=True;" } }
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions
protected override void OnModelCreating(ModelBuilder modelBuilder) { //... }
//... }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext
//... }
通过这些步骤,应用程序将能够正确找到并使用命名连接字符串。