我正在使用ASP.NETWeb API Core 2.0 w/EntityFramework,用于连接到AWS MariaDB实例。
当我用本地连接运行webapi时,一切正常。
public class ApplicationDbContext : IdentityDbContext<AppUser>
{
public ApplicationDbContext(DbContextOptions options)
: base(options)
{
}
public DbSet<AppUser> AppUsers { get; set; }
public DbSet<Profile> Profiles { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<AppUser>().ToTable("aspnetusers");
builder.Entity<Profile>().ToTable("profiles");
base.OnModelCreating(builder);
}
}
注意:对profile的api调用工作正常。
services
.AddDbContext<ApplicationDbContext>(
options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection")))
.AddUnitOfWork<ApplicationDbContext>();
编辑:
本地与aws的连接字符串格式
服务器=localhost;用户Id=root;密码=xxxxxxx;数据库=CoolAppDB
服务器=coolappdb.1234564798.us-west-2。rds.amazonaws.com网站;端口=3306;用户Id=用户名;密码=xxxxxxx;数据库=coolappdb