I'm building MVC Core app using Visual Studio Code on Mac OS.
I created MVC app using yeo generator working with database EF core, everything works fine on localhost. I put correct connection string for my Azure SQL Server db in appsettings.json and ran app from Azure link but got error - "An error occurred while
starting the application." without any details.
I checked my Azure by Kudu "http://<yoursitename>.scm.azurewebsites.net", the files are uploaded properly.
I also had a chance to check my Azure SQL using SQL Server Management Studio on Windows, my database is well published.
In my Azure, I got Web App Service, SQL sever(V12), SQL database under the same Resource name. All of their status are online and running.
I did quite a lot of research online for my problem but still got stuck for 2 days.... Please help!!!
What I did was:
1. dotnet ef migrations add InitialCreate -c ApplicationDbContext ==> Compilation succeeded.
2. dotnet ef database update -c ApplicationDbContext ==> Compilation succeeded.
3. dotnet run ==> Compilation succeeded.
Output of step 3:
info: Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory[1] Executed DbCommand (373ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE') SELECT 1 ELSE SELECT 0 ............... // doing DB seeding info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0] User profile is available. Using '/Users/matt/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest. Hosting environment: Production Content root path: /Users/matt/Documents/MyApp Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down.
4. git push -u azure master ==> Deployment successful.
Output of step 4:
............... // doing remote stuffs remote: Finished successfully. remote: Running post deployment command(s)... remote: Deployment successful. To https://myapp.scm.azurewebsites.net:443/myapp.git 85eecb5..914a2a0 master -> master Branch master set up to track remote branch master from azure.
appsetting.json:
{"ConnectionStrings": {"DefaultConnection": "Server=tcp:myapp-test.database.windows.net,1433 ;Initial Catalog=myapp-test;Persist Security Info=False;User ID=<remove from blog>;Password=<remove from blog>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},"Logging": {"IncludeScopes": false,"LogLevel": {"Default": "Debug","System": "Information","Microsoft": "Information"
}
}
}Configure method in Startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ApplicationDbContext context)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddJsonFile(env.ContentRootPath + "/config.json")
.Build();
if (configuration.GetValue<bool>("EnableDeveloperExceptions"))
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseIdentity();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
// Create database on startup
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
}
DbInitializer.Initializer(context);
}web.config:
<?xml version="1.0" encoding="utf-8"?><configuration><system.webServer><handlers><add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/></handlers><aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/></system.webServer></configuration>