I am trying to connect web api made in asp.net to sql server database provided by aws rds. I have never used aws before so I am not really sure if I am missing something there. I have tried to do it but i get following message when I added migration and trying to update database (using EF core):
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I have following code in my API:
Context class:
public class TestContext : DbContext
{
public virtual DbSet<Fruit> Fruits { get; set; }
public TestContext(DbContextOptions<TestContext> options) : base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("server=<nameofserver>;user=<username>;password=<password>;database=<nameofdatabase>;"); // there i put data from my database hosted on aws
}
}
and in Program.cs:
builder.Services.AddDbContext<TestContext>(options =>
options.UseSqlServer("server=<nameofserver>;user=<username>;password=<password>;database=<nameofdatabase>;"))// there i put data from my database hosted on aws1;
I know I should put connection string in appsettings.json but I believe that is not the case now. Why isn't the table being created in the database? Should i enable/do sth on aws website? Or maybe the problem is in the code? How can I solve it?