.NET Core Entity Framework on AWS

Viewed 1085

I've got a web application written in .NET Core using Entity Framework to connect to a SQL Server database. Everything works fine locally. The staging/production environment for the app is AWS Elastic Beanstalk, and I seem to be stuck on how to get the app to connect to the database there.

I've created an RDS (SQL Server) database underneath the Elastic Beanstalk app.

Connection string:

user id=[USER];password=[PASSWORD];Data Source=[SERVER].rds.amazonaws.com:1433;Initial Catalog=Development

Creating the DbContext:

services.AddDbContext<MyDbContext>(o =>
                o.UseSqlServer(Configuration["Db:ConnectionString"]));

App fails to start, based on the following line in Startup.cs:

dbContext.Database.EnsureCreated();
1 Answers

You have to troubleshoot step by step as below procedure:

  1. Db Connection string is working or not? Better to use with other app and simple doing the Db Connection testing. It could be possible that firewall block your port 1433.
  2. As per your codes, .NET Core Framework will crate a database by code first approach. So that, you have to make sure, your IIS Application Pool user account has write access to SQL Database. Most probability it could be your problem.
Related