Azure deployment of ASP.net MVC project incomplete

Dean Everhart 1,496 Reputation points
2021-09-13T08:20:32.22+00:00

I have a ASP.net MVC project deployed to Azure.

Website works and links in navigation bar navigate to MVC CRUD views in the url but there is no data.

Microsoft SQL Server Management Studio shows database structure with no data. on Azure. The columns / properties include past versions of properties from all the previous code-based migrations...so the properties / columns, though present on Azure, are not up-to-date.

I think my next step is to use drop create database when model changes or always to get current database properties and data up to Azure. I'm not exactly sure how to write the code for this. below is first unsuccessful attempt in context file.

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 // end default
 // using System.Data.Linq;     CreateDatabase
 // using System.Data;          CreateDatabase
 // using System.Data.Object;   CreateDatabase
 using alpha.Models;
 using System.Data.Entity;
 using System.Data.Entity.ModelConfiguration.Conventions;

 namespace alpha.Data
 {
     public class alphaContext : DbContext
     {
         public alphaContext() : base("alphaContext") // The name of the connection string is passed in to the constructor.
         {
             // Database.SetInitializer<alphaContext>(new CreateDatabaseAlways<alphaContext>());
         }
         public DbSet<item> items { get; set; }

         protected override void OnModelCreating(DbModelBuilder modelBuilder)
         {
             modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
         }
     }
 }
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,250 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,858 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 25,486 Reputation points Microsoft Employee
    2021-09-13T21:01:13.347+00:00

    Hi @DeanAndrewEverhart-9294,

    I would advise reviewing Tutorial: Deploy an ASP.NET app to Azure with Azure SQL Database for deploy an ASP.NET MVC app with a SQL backend to Azure. It outlines the steps to configure your app service and Azure SQL instance, publishing your app to the app service, and applying migrations to create the schema.

    Having said, you asked several questions in your linked document, which I did remove due to it containing sensitive information.

    Visual Studio Publish, 443 works (1433 does not work?)

    When publishing to an App Service, deployment is done through Kudu which is accessible securely from https://<your-app-name>.scm.azurewebsites.net on port 443. Port 1433 is the port SQL Server instances opens to allow for database connectivity. It is specific to SQL and will never be used to for deployment

    Database fields and structure present but no data and properties viewed through MSSMS include properties that have been altered in later code-first migrations.

    If you're notice that database columns, types, etc. are being left over from migration to migration, inspect the protected override void Up(MigrationBuilder migrationBuilder) method in the migration. When running Add-Migration, the Up(MigrationBuilder migrationBuilder) should contain the modified database schema based off the DbSets<TEntity> added to your DbContext.

    As for the data, your data seeding method should be called during the startup of your program. In ASP.NET MVC, this means initializing your DbContext object in the class decorated with [assembly: OwinStartup()] and calling your seeding method, see https://www.learnentityframeworkcore.com/migrations/seeding for various methods on how you can seed data to your context.


0 additional answers

Sort by: Most helpful