Error of the underlying provider in Open

1

I have an error that says: Error of the underlying provider in Open, and in in innerexcepcion says:

  

{"Timeout value expired." The timeout period   It ran out during the pre-session start phase. It is possible that the   connection will time out while waiting for the server   complete the login process and respond; or, at   try to create several active connections. The time spent to   Trying to connect to this server was: [Previous to login]   initialization = 13443; link protocol = 1; [Login]   initialization = 0; authentication = 34; [After the start of session]   full = 4176; "}

The line of the error where it says: Dim total_listadoNoticia = list_noticia.ToList.Count

Dim list_noticia = From f In db.NOTICIA Select New With {.IdNoticia =    f.IdNoticia, .TituloNoticia = f.TituloNoticia, .DescripcionNoticia = f.DescripcionNoticia, .FechaPublicacionNoticia = f.FechaPublicacionNoticia}
Dim total_listadoNoticia = list_noticia.ToList.Count ' aquí se cae

the amount of data that is listed in Count is enough, in fact one of the attributes of the table NOTICIA is binary (f.FotoPortada), but it is removed.

In the webconfig I put this to solve the problem:

<httpRuntime executionTimeout="600" maxRequestLength="4194304" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" />

but nothing.

This problem occurs only the first time after running the Visual Studio , if I run it again, the error does not appear.

I would like to know how to optimize my query of linq making it more efficient, avoiding this type of problem and if it were not possible, like giving more memory or some capacity in webconfig or wherever to avoid this kind of problems .

complete code:

Function partialListadoNoticia(ByVal pag As Integer) As ActionResult
    Using db As New BD_LOSCOPIHUESEntities1
        Dim cant_filas As Integer = 5
        Dim ind_pag As Integer = (cant_filas - 1) * pag


        Dim l As New ListadoNoticiasViewModel
        Dim listadoNoticia_q = (From noti In db.NOTICIA.Include("FOTO") Select noti Order By noti.FechaPublicacionNoticia Descending)
        Dim total_listadoNoticia = db.NOTICIA.Count

        Dim ultima_paginaDouble As Decimal = total_listadoNoticia / cant_filas
        Dim ultima_paginaEntero As Integer = Decimal.Round(ultima_paginaDouble, 0)

        If ultima_paginaDouble > ultima_paginaEntero Then
            ultima_paginaEntero = ultima_paginaEntero + 1
        End If

        l.listadoNoticias = listadoNoticia_q.Skip(ind_pag).Take(cant_filas).ToList()
        ViewData("totalListadoNoticia") = total_listadoNoticia
        ViewData("ultimaPagina") = ultima_paginaEntero
        ViewData("pagina_actual") = pag ' esto es para paginación

        Return View(l)
    End Using

End Function

In Dim total_listadoNoticia = db.NOTICIA.Count , is where the error indicates

    
asked by Danilo 07.02.2016 в 04:02
source

1 answer

1

What happens if you just define

Dim total_listadoNoticia As Integer = db.NOTICIA.Count();

If the idea is just to count the entities in the table.

If the entity has a field with a photo it would be advisable to implement Table Splitting , with this you could map several classes of .net to the same table, being able to recover only some of the basic fields.

[Entity Framework] [Code First] Divide Table

In your case, the main properties are defined in the main class and for example, the image field is defined in a separate entity, so when retrieving with the query, you do not penalize the query.

You could see to extend the timeout of that command

Using db As New BD_LOSCOPIHUESEntities1
   db.Database.CommandTimeout = 180;

End Using

Set database timeout in Entity Framework

This way you would give time to run when you start the application

    
answered by 07.02.2016 / 04:12
source