And the culprit is ...

I was so happy yesterday to found a solution to the General Network Error.

However this morning, I still received few of them, so I decided to find the culprit.

And I got it, it's the Data Application Block I use in many cases. It's a great stuff to have an SQL helper, but it seems for me it's a bit buggy.

After replacing my code with a classic datareader, everything is ok now. Maybe the helper is too chatty :-)

Now I have reduced by half the number of 'random' errors. It seems that if I force a dispose method after closing the connections, I have a better result.

Unfortunately for some unknown reason, I can't use a dispose in the method I use to generate an image from a database. If I do, I have no images at all. I can close the connection, but nothing more.

I know it's not perfect, if the error happens, a broken link appears for an image, but at least the page content is shown, and that matters.

 

8 Comments

  • Interesting, I've never seen this error though I 've used the block in literally dozens of applications (DAAB v2 to be precise). The block isn't any more 'chatty' than any normal way of accessing data (indeed, if you use the SqlHelperParameterCache it can actually reduce your roundtrips).

  • Hi Scott. Yes maybe. Anyway I still have few errors from the same method. And it's the only one where I don't dispose my connection. If I try I don't have any images.



    Public Function GetImage(ByVal ThumbnailId As Integer) As System.Drawing.Bitmap

    Dim dr As SqlDataReader

    Dim objCommand As New SqlCommand("Image_GetByID", m_Connection)



    Try

    'Dim Params() As SqlParameter = New SqlParameter(1) {}



    'Params(0) = New SqlParameter("@ImageId", ThumbnailId)

    objCommand.CommandType = CommandType.StoredProcedure

    objCommand.Parameters.Add("@ImageID", SqlDbType.Int).Value = ThumbnailId

    m_Connection.Open()

    dr = objCommand.ExecuteReader(CommandBehavior.CloseConnection)



    If dr.Read Then



    Dim b() As Byte = CType(dr("ImageData"), Byte())



    If b.Length > 0 Then

    ' Open a stream for the image and write the bytes into it

    Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream(b, True)

    stream.Write(b, 0, b.Length)



    ' Create a bitmap from the stream

    Dim bmp As New Bitmap(stream)



    ' Close the stream

    stream.Close()



    Return bmp

    End If

    Return Nothing

    End If



    Catch ex As Exception

    Throw New Exception(ex.Message)

    Return Nothing

    Finally

    If Not (m_Connection Is Nothing) Then

    If m_Connection.State = ConnectionState.Open Then

    m_Connection.Close()

    'This is where I try m_connection.dispose. Strangely this has fixed the problem in some other methods, but here create a broken image link

    End If

    End If

    End Try



    End Function

  • The previous solution, before I installed the switches, was to set tje pooling to false in my connection strings.

  • in my case the error was microfractures: the network dropping to the floor for a few microseconds creating "voids", which would truncate the connection

  • stefan never heard about that before. Can you give more details ?

  • Wierd...I had this previously with a 'broken' install of .NET 1.1 - where I'd get random GNEs all over the place in a previously functional app. One thing you might want to look at is holding your connection open for the minimum possible time. So in the code above you can declare your byte array outside the Data Access code and just populate it then immediately close your DataReader (which I notice you don't do here...I normally use C# so I wrap readers and connections in using{} blocks) and the underlying connection (if necessary, but closing your reader should close the connection since you specified CommandBehavior.CloseConnection).

  • I follow your advice and now I close the datareader twice, one using the Commandbehavior.closeconnection and one dr.close() after the byte reading.

    We'll see, seems to be ok for the moment

  • Yes I know but I tried and weird, I have better results. Well still receive a couple of errors, but now I talk about 3 to 4 per hour compare to the hundreds per minute two days ago.

    More weird, I still don't know where exactly is the problem after one year of research on the subject !

Comments have been disabled for this content.