Some days ago me and my Project Leader Mario have been invoiced of find the reason of IIS’s Error 500 on a web application we’re testing.
This error came out only under web application’s stress test and it was really strange… Error 500 is a Server Error and we were thinking about MSSQL connection pool, IIS parameters and so on.
On last try we installed a packet sniffer (WireShark, old Ethereal) and monitoring we find that under some cirumstance MSSQL server won’t read a data from DB.
Stepping throught the code, we found this :
Public Shared Function getUnionLogo(ByVal intUnionID As Int32) As Byte()
Dim strConn As String
Dim parms(0) As SqlParameter
Dim dr As SqlDataReader
Dim lngImageLength As Long
Dim ImageArray As Byte()
parms(0) = New SqlParameter(“@UnionID”, SqlDbType.Int)
parms(0).Value = intUnionID
strConn = Common.GetConfigSettings(“ConnectionString_Apps”)
Try
dr = SqlHelper.ExecuteReader(strConn, “usp_GetUnionLogo”, parms)
If dr.Read Then
lngImageLength = dr.GetBytes(0, 0, Nothing, 0, Integer.MaxValue)
ReDim ImageArray(lngImageLength)
dr.GetBytes(0, 0, ImageArray, 0, Convert.ToInt32(lngImageLength))
dr.Close()
End If
Catch y As SqlException
End Try
Return ImageArray
End Function
As I’ve mentioned above, on some circumstances, this function screw up and it’s due to this :
They declare Dim ImageArray As Byte() but they redim it (VB is really a freaky language….wtf u redim….) into try{} catch{} statement without considering that the GetBytes above may fail.. if this happens the function returns ImageArray as a null pointer, excuse me nothing pointer (I have VB more and more each time I use it, first WHY don’t use bratchets and ;???)
We’ve fixed it and here’s our solution..
Public Shared Function getUnionLogo(ByVal intUnionID As Int32) As Byte()
Dim strConn As String
Dim parms(0) As SqlParameter
Dim dr As SqlDataReader
Dim lngImageLength As Long
Dim ImageArray(0) As Byte
parms(0) = New SqlParameter(“@UnionID”, SqlDbType.Int)
parms(0).Value = intUnionID
strConn = Common.GetConfigSettings(“ConnectionString_Apps”)
Try
dr = SqlHelper.ExecuteReader(strConn, “usp_GetUnionLogo”, parms)
If dr.Read Then
‘lngImageLength = dr.GetBytes(0, 0, Nothing, 0, Integer.MaxValue)
lngImageLength = dr.GetInt32(1) ‘I read logo datalenght
If lngImageLength > 0 Then
ReDim ImageArray(lngImageLength – 1)
dr.GetBytes(0, 0, ImageArray, 0, lngImageLength)
End If
End If
dr.Close()
Catch y As SqlException
ReDim ImageArray(1)
End Try
Return ImageArray
For doing this, we’ve added into the store procedure on MSSQL a function to get image lenght….
there’re many many errors on this solution and we’ll try to catch{} and fix{} as much as possible!
Italian do it better………remember it!
Leave a Reply