1

Тема: blazor db connection error

Створив blazor server app with individual authentication type. Чомусь під час запуску додатку видає помилку підключення до БД.

/Users/sashamaksyutenkoadmin/Documents/BlazorApp2024/BlazorApp2024/bin/Debug/net9.0/BlazorApp1
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5007
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /Users/sashamaksyutenkoadmin/Documents/BlazorApp2024/BlazorApp2024
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database 'YumBlazor' on server 'localhost,1433'.

Коли реєструю нового користувача то він додається до AspNetUsers в БД, але сторінка не грузиться. Проблема не в стрічці підключення швидше всього.
https://github.com/SashaMaksyutenko/BlazorApp2024

2

Re: blazor db connection error

https://replace.org.ua/uploads/images/10138/358a717f7d8f1b7fe8ea233b754cedf2.jpg

Тільки спінер при завантаженні

3

Re: blazor db connection error

?????

4

Re: blazor db connection error

ось детальніші логи:

      Hosting starting
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5007
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /Users/sashamaksyutenkoadmin/Documents/BlazorApp2024/BlazorApp2024
dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
      Hosting started
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect.
dbug: Microsoft.EntityFrameworkCore.Infrastructure[10401]
      An 'IServiceProvider' was created for internal use by Entity Framework.
dbug: Microsoft.EntityFrameworkCore.Model[10601]
      The index {'UserId'} was not created on entity type 'IdentityUserRole<string>' as the properties are already covered by the index {'UserId', 'RoleId'}.
dbug: Microsoft.EntityFrameworkCore.Model[10601]
      The index {'UserId'} was not created on entity type 'IdentityUserToken<string>' as the properties are already covered by the index {'UserId', 'LoginProvider', 'Name'}.
dbug: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 9.0.0 initialized 'ApplicationDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:9.0.0' with options: EngineType=SqlServer 
dbug: Microsoft.EntityFrameworkCore.Query[10111]
      Compiling query expression: 
      'DbSet<ShoppingCart>()
          .Where(u => u.UserId == __userId_0)'
dbug: Microsoft.EntityFrameworkCore.Query[10107]
      Generated query execution expression: 
      'queryContext => SingleQueryingEnumerable.Create<ShoppingCart>(
          relationalQueryContext: (RelationalQueryContext)queryContext, 
          relationalCommandResolver: parameters => [LIFTABLE Constant: RelationalCommandCache.QueryExpression(
              Projection Mapping:
                  EmptyProjectionMember -> Dictionary<IProperty, int> { [Property: ShoppingCart.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: ShoppingCart.Count (int) Required, 1], [Property: ShoppingCart.ProductId (int) Required FK Index, 2], [Property: ShoppingCart.UserId (string) FK Index, 3] }
              SELECT s.Id, s.Count, s.ProductId, s.UserId
              FROM ShoppingCart AS s
              WHERE s.UserId == @__userId_0) | Resolver: c => new RelationalCommandCache(
              c.Dependencies.MemoryCache, 
              c.RelationalDependencies.QuerySqlGeneratorFactory, 
              c.RelationalDependencies.RelationalParameterBasedSqlProcessorFactory, 
              Projection Mapping:
                  EmptyProjectionMember -> Dictionary<IProperty, int> { [Property: ShoppingCart.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: ShoppingCart.Count (int) Required, 1], [Property: ShoppingCart.ProductId (int) Required FK Index, 2], [Property: ShoppingCart.UserId (string) FK Index, 3] }
              SELECT s.Id, s.Count, s.ProductId, s.UserId
              FROM ShoppingCart AS s
              WHERE s.UserId == @__userId_0, 
              False, 
              new HashSet<string>(
                  new string[]{ }, 
                  StringComparer.Ordinal
              )
          )].GetRelationalCommandTemplate(parameters), 
          readerColumns: null, 
          shaper: (queryContext, dataReader, resultContext, resultCoordinator) => 
          {
              ShoppingCart entity;
              entity = 
              {
                  MaterializationContext materializationContext1;
                  IEntityType entityType1;
                  ShoppingCart instance1;
                  InternalEntityEntry entry1;
                  bool hasNullKey1;
                  materializationContext1 = new MaterializationContext(
                      [LIFTABLE Constant: ValueBuffer | Resolver: _ => (object)ValueBuffer.Empty], 
                      queryContext.Context
                  );
                  instance1 = default(ShoppingCart);
                  entry1 = queryContext.TryGetEntry(
                      key: [LIFTABLE Constant: Key: ShoppingCart.Id PK | Resolver: c => c.Dependencies.Model.FindEntityType("BlazorApp1.Data.ShoppingCart").FindPrimaryKey()], 
                      keyValues: new object[]{ (object)dataReader.GetInt32(0) }, 
                      throwOnNullKey: True, 
                      hasNullKey: hasNullKey1);
                  !(hasNullKey1) ? entry1 != default(InternalEntityEntry) ? 
                  {
                      entityType1 = entry1.EntityType;
                      return instance1 = (ShoppingCart)entry1.Entity;
                  } : 
                  {
                      ISnapshot shadowSnapshot1;
                      shadowSnapshot1 = [LIFTABLE Constant: Snapshot | Resolver: _ => Snapshot.Empty];
                      entityType1 = [LIFTABLE Constant: EntityType: ShoppingCart | Resolver: namelessParameter{0} => namelessParameter{0}.Dependencies.Model.FindEntityType("BlazorApp1.Data.ShoppingCart")];
                      instance1 = switch (entityType1)
                      {
                          case [LIFTABLE Constant: EntityType: ShoppingCart | Resolver: namelessParameter{1} => namelessParameter{1}.Dependencies.Model.FindEntityType("BlazorApp1.Data.ShoppingCart")]: 
                              {
                                  return 
                                  {
                                      ShoppingCart instance;
                                      instance = new ShoppingCart();
                                      instance.<Id>k__BackingField = dataReader.GetInt32(0);
                                      instance.<Count>k__BackingField = dataReader.GetInt32(1);
                                      instance.<ProductId>k__BackingField = dataReader.GetInt32(2);
                                      instance.<UserId>k__BackingField = dataReader.IsDBNull(3) ? default(string) : dataReader.GetString(3);
                                      (instance is IInjectableService) ? ((IInjectableService)instance).Injected(
                                          context: materializationContext1.Context, 
                                          entity: instance, 
                                          queryTrackingBehavior: TrackAll, 
                                          structuralType: [LIFTABLE Constant: EntityType: ShoppingCart | Resolver: namelessParameter{2} => namelessParameter{2}.Dependencies.Model.FindEntityType("BlazorApp1.Data.ShoppingCart")]) : default(void);
                                      return instance;
                                  }}
                          default: 
                              default(ShoppingCart)
                      }
                      ;
                      entry1 = entityType1 == default(IEntityType) ? default(InternalEntityEntry) : queryContext.StartTracking(
                          entityType: entityType1, 
                          entity: instance1, 
                          snapshot: shadowSnapshot1);
                      return instance1;
                  } : default(void);
                  return instance1;
              };
              return entity;
          }, 
          contextType: BlazorApp1.Data.ApplicationDbContext, 
          standAloneStateManager: False, 
          detailedErrorsEnabled: False, 
          threadSafetyChecksEnabled: True)'
dbug: Microsoft.EntityFrameworkCore.Database.Connection[20005]
      Creating DbConnection.
dbug: Microsoft.EntityFrameworkCore.Database.Connection[20006]
      Created DbConnection. (12ms).
dbug: Microsoft.EntityFrameworkCore.Database.Connection[20000]
      Opening connection to database 'YumBlazor' on server 'localhost,1433'.
dbug: Microsoft.EntityFrameworkCore.Infrastructure[10407]
      'ApplicationDbContext' disposed.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database 'YumBlazor' on server 'localhost,1433'.
dbug: Microsoft.EntityFrameworkCore.Database.Connection[20007]
      Disposing connection to database 'YumBlazor' on server 'localhost,1433'.
dbug: Microsoft.EntityFrameworkCore.Database.Connection[20008]
      Disposed connection to database '' on server '' (0ms).
dbug: Microsoft.EntityFrameworkCore.Query[10115]
      A query was canceled for context type 'BlazorApp1.Data.ApplicationDbContext'.
Error in GetTotalCartCartCountAsync: A task was canceled.
^Cinfo: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...
dbug: Microsoft.Extensions.Hosting.Internal.Host[3]
      Hosting stopping
dbug: Microsoft.Extensions.Hosting.Internal.Host[4]
      Hosting stopped
➜  BlazorApp2024 git:(main) ✗