Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Day 3 - Changes to sample web application #487

Open
Freshchris01 opened this issue Sep 15, 2022 · 0 comments
Open

Day 3 - Changes to sample web application #487

Freshchris01 opened this issue Sep 15, 2022 · 0 comments

Comments

@Freshchris01
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant