Base solution for your next web application
Open Closed

Sql View not show in frondend angular #11082


User avatar
0
billyteng created

"version": "11.1.0", Angular net core

I have a sql view which use old project. Now i use that sql server view in asp.net zero project. I wrote customize repository like you reference. Then I run project. It is ok in server. The server reterive datas depend view query. But there is showing "An internal error occurred" message in frontend angular. I have alreay debug on server side. Serverside is ok. Please help me. You can see my codes. I'm looking forward your answer.

application.shared layer public class viewReservationFolio : CreationAuditedEntity<Guid> {
...... }

 public class InputSearch : PagedAndSortedResultRequestDto
{       
   ....
}  

EntityFrameworkCore Layer

  public class ReservationRepository : BEZNgCoreRepositoryBase&lt;viewReservationFolio, Guid&gt;, IReservationRepository
{
    private readonly IActiveTransactionProvider _transactionProvider;

    public ReservationRepository(IDbContextProvider&lt;BEZNgCoreDbContext&gt; dbContextProvider, IActiveTransactionProvider transactionProvider)
        : base(dbContextProvider)
    {
        _transactionProvider = transactionProvider;
    }
    public async Task&lt;List&lt;viewReservationFolio&gt;> GetViewReservationFolio(InputSearch input)
    {
        var sqlText = QueryText(input);
        var result = new List&lt;viewReservationFolio&gt;();
        if ((input.IsCompany == false && input.IsGroup == false) || (input.IsCompany == true && input.IsGroup == true && input.IsCancel == false && input.IsPending == false && input.IsNoShow == false &&
            input.IsReservation == false && input.IsHouse == false && input.IsCheckOut == false))
        {
            result = new List&lt;viewReservationFolio&gt;();
        }           
        else
        {
            await EnsureConnectionOpenAsync();
            var arams = GetParameterValue(input);
            using (var command = CreateCommand(sqlText, CommandType.Text, arams))
            {
                using (var dataReader = await command.ExecuteReaderAsync())
                {
                    try
                    {
                        while (await dataReader.ReadAsync())
                        {
                            viewReservationFolio v = new viewReservationFolio();                                                            
                            ........                             
                            result.Add(v);

                        }
                        dataReader.Close();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            await EnsureConnectionCloseAsync();
        }

        return result;

    }      

Core Layer public interface IReservationRepository : IRepository<viewReservationFolio, Guid> {
Task<List<viewReservationFolio>> GetViewReservationFolio(InputSearch input); }

Application Layer
[AbpAuthorize(AppPermissions.Pages_Reservations)]
public class ReservationAppService : BEZNgCoreAppServiceBase, IReservationAppService
{
    private readonly IApplicationLanguageManager _applicationLanguageManager;
..........................
    public ReservationAppService(
        IApplicationLanguageManager applicationLanguageManager,
     ...................)
    {
        _applicationLanguageManager = applicationLanguageManager;
       .....
    }

    public async Task&lt;List&lt;StayDateDto&gt;> GetStayDate()
    {           
        
    }              
    
    public async Task&lt;PagedResultDto&lt;GetReservationFolioDto&gt;> GetViewReservationFolioToday(InputSearch input)
    {            
        var vw = _reservationRepository.GetViewReservationFolio(input);
        var pagedAndFilteredRegistration = vw.Result.AsQueryable();
        pagedAndFilteredRegistration=pagedAndFilteredRegistration.OrderBy(input.Sorting ?? "CheckInDate,DocNo asc").PageBy(input);

        var totalCount = pagedAndFilteredRegistration.Count();

        var dbList = pagedAndFilteredRegistration.ToList();
        var results = new List&lt;GetReservationFolioDto&gt;();

        foreach (var o in dbList)
        {
            var res = new GetReservationFolioDto()
            {
                GetViewResFolio = ObjectMapper.Map&lt;viewReservationFolioDto&gt;(o)
            };

            results.Add(res);
        }

        return new PagedResultDto&lt;GetReservationFolioDto&gt;(
            totalCount,
            results
        );
        
    }

Note: results list incluse datas.

Log File

INFO 2022-05-23 01:20:11,930 [orker] osoft.EntityFrameworkCore.Infrastructure - Entity Framework Core 6.0.0 initialized 'BEZNgCoreDbContext' using provider 'Microsoft.En ERROR 2022-05-23 01:20:21,678 [orker] Mvc.ExceptionHandling.AbpExceptionFilter - This SqlTransaction has completed; it is no longer usable. System.InvalidOperationException: This SqlTransaction has completed; it is no longer usable.

INFO 2022-05-23 01:20:21,691 [orker] c.Infrastructure.ControllerActionInvoker - Executed action BEZNgCore.Reservations.ReservationAppService.GetViewReservationFolioToday (BEZNgCore.Application) in 11899.6915ms INFO 2022-05-23 01:20:21,691 [orker] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'BEZNgCore.Reservations.ReservationAppService.GetViewReservationFolioToday (BEZNgCore.Application)' INFO 2022-05-23 01:20:21,691 [orker] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished HTTP/2 GET https://localhost:port/api/services/app/Reservation/GetViewReservationFolioToday?Filter=&StayDate=default&IsReservation=true&IsHouse=true&IsCheckOut=true&IsCompany=true&IsGroup=true&FirstName=&LastName=&RoomNo=&FolioNo=&CompanyName=&GroupName=&VoucherNo=&TelNo=&MobileNo=&Email=&Passport=&RateCode=&LoyaltyNo=&AccNo=&PostalCode=&GDS=&Group1Key=&Group2Key=&Group3Key=&Group4Key=&RateTypekey=&Sorting=&SkipCount=0&MaxResultCount=10 - - - 500 207 application/json;+charset=utf-8 11953.9042ms INFO 2022-05-23 01:20:23,974 [orker] osoft.EntityFrameworkCore.Infrastructure - Entity Framework Core 6.0.0 initialized 'BEZNgCoreDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.0' with options: None

Frontend https://localhost:port/api/services/app/Reservation/GetViewReservationFolioToday?.. {"result":null,"targetUrl":null,"success":false,"error":{"code":0,"message":"An internal error occurred during your request!","details":null,"validationErrors":null},"unAuthorizedRequest":false,"__abp":true}


9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @billyteng

    Your code seems fine at first look. Is it possible to share your project via email ([email protected]) ? We can check it locally for you.

    Thanks

  • User Avatar
    0
    billyteng created

    HI ismcagdas I have already sent project file to your reference email. Please check it.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @billyteng

    Thanks, we got the project. I have requested the view's script via email.

  • User Avatar
    0
    billyteng created

    HI ismcagdas

    Our view is bit complicated and need many table to create. I have already sent. Please check.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @billyteng

    We acn continue via email for this problem. I requested additional resources.

    Thanks,

  • User Avatar
    0
    billyteng created

    HI ismcagdas

    I have already sent db file to your reference email. Please check it.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @billyteng

    Could you add below attribute to your GetViewReservationFolioToday method ? It worked for me.

    [UnitOfWork(isTransactional: false)]
    

    The final method will be like this;

    [UnitOfWork(isTransactional: false)]
    public async Task<PagedResultDto<GetReservationFolioDto>> GetViewReservationFolioToday(InputSearch input)
    {
        // method content...
    }
    
  • User Avatar
    0
    billyteng created

    Hi @ismcagdas

    It's ok now. Thanks million. Great team and support.

    Thanks all

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks :)