Day 3 - Changes to sample web application
Freshchris01 opened this issue · 0 comments
Freshchris01 commented
In day 3 - challenge 2, there is an optional part. In this part we connect the SQL database to a sample web application.
The application code is hosted here. As there were changes in this code, our instructions are outdated.
Partial steps for resolution:
- Step 5: change
--client
argument to ado.net - Step 12: change Startup.cs to Program.cs
- Step 13: change code changes to:
// Use SQL Database if in Azure, otherwise, use SQLite
if(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Production")
builder.Services.AddDbContext<MyDatabaseContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("MyDbConnection")));
else
builder.Services.AddDbContext<MyDatabaseContext>(options =>
options.UseSqlite("Data Source=localdatabase.db"));
// Automatically perform database migration
builder.Services.BuildServiceProvider().GetService<MyDatabaseContext>().Database.Migrate();
- Add step to allow connection to the SQL database. Maybe use the checkbox option to allow traffic from Azure services?
When I then try to add a new todo item with the webapp, the following error occurs:
Operand type clash: datetime2 is incompatible with textat Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__188_0(Task`1 result)at
Improvement:
- Step 9: add remark to save the DeploymentLocalGitUrl from the output. It is needed in step 15
So there is some work left todo to fix the example.