question

DeanEverhart avatar image
0 Votes"
DeanEverhart asked DeanEverhart commented

Azure deployment of ASP.net MVC project incomplete

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>();
          }
      }
  }


azure-webapps-content-deploymentdotnet-aspnet-webpages
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ryanchill avatar image
0 Votes"
ryanchill answered DeanEverhart commented

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.
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Ryan - Thanks for the response and the help.

the port information is new to me, so I'm thrilled to learn that.

I'm trying to figure out deploying and troubleshooting deploying data to Azure. The question, for me, is what do you do when creating a project on Azure does not work as the directions or tutorial predicts it will. I created the database, server, service plan, and resource group and I've used publish to create the website (which is active...works to a degree): but I can't get local data to upload to Azure.

Seeding data - please correct me if I'm wrong, but trying to get a local database up to Azure is not seeding data (or perhaps I'm wrong). I don't think I'm technically seeding data. I already have a database. I need to get that local database up to Azure. This is where I'm having the trouble.

Thanks again for the response. Please correct me if I'm wrong about anything above.

I rephrased question anew in a newly posted question.

0 Votes 0 ·