Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  OutOfMemoryException (Thursday, January 27, 2005)




Found the following interesting discussion in the Newsgroups:

OutOfMemoryException
by:Fredrik Melin

In the following code I get an OutOfMemoryException when trying to store a
16.7 MB file. (16773738 bytes)

The error is raised on the code: Dim b(fs.length-1) as Byte

Is there a limit on how large byte array you can declare? If so, How can I
store the file in the database?
Regards
Fredrik Melin

/// CODE BELOW
Dim dbConn As SqlClient.SqlConnection
Dim cmSQL As New SqlClient.SqlCommand("UPDATE
EDI_MESSAGE_QUE SET XML_MESSAGE_CONVERTED = @BLOB WHERE BATCH_ID_XREF =
@BATCH_ID", dbConn)

Try
If dbTrans Is Nothing Then
dbConn = New
SqlClient.SqlConnection(DacsaSystemObject.ConnectionObject.sConnection_Strin
g)
dbConn.Open()

dbTrans =
dbConn.BeginTransaction(IsolationLevel.Serializable)
bLocalTransaction = True
Else
dbConn = dbTrans.Connection
End If

cmSQL.Connection = dbConn
cmSQL.Transaction = dbTrans

cmSQL.CommandTimeout = 900

Dim fs As New System.IO.FileStream(File_Name,
System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim b(fs.Length - 1) As Byte
fs.Read(b, 0, b.Length)

fs.Close()
Dim P As New SqlClient.SqlParameter("@BLOB",
SqlDbType.Image, b.Length, ParameterDirection.Input, False, 0, 0, Nothing,
DataRowVersion.Current, b)
cmSQL.Parameters.Add(P)

cmSQL.Parameters.Add("@BATCH_ID", Batch_ID)
If cmSQL.ExecuteNonQuery = 0 Then
Throw New Dacsa_Exceptions.Critical("Failure to save
XML Message que job")
End If

Erase b
b = Nothing

If bLocalTransaction Then dbTrans.Commit()

'RaiseEvent Status_Changed("Message saved!")
Return True

Catch ex As Exception
ErrReport.RegisterError(ex)
Finally
If bLocalTransaction Then dbConn.Close()
cmSQL.Dispose()

End Try



 Reply:
by:Supra

 i had same problem while i was doing picture puzzle using vb.net window.

can u change byte to integer or long?

regards


 Reply:
by:Fredrik Melin

 Problem is that fileStream dont like integer or long...

Strange:

Dim b(16773738) As Byte does NOT work

Dim b(17773738) As Byte WORKS!


 Reply:
by:Fredrik Melin

 Ah....

http://support.microsoft.com/?kbid=826981


 Reply:
by:Supra

 good for u.
i used to too that b4.
regards,








0 Comments:

Post a Comment

 
Previous Posts
    - How to transfer values bewteen Integer and UInt32 ...
    - How to transfer values between Integer and UInt32 ...
    - How to set file persmissions with WMI using a UNC ...
    - Week date
    - How to set a dataset date value to null
    - If only MSDN examples would actually work!
    - How to use managed code in Office 2003
    - Click Event not fired
    - How to read a particular setting from a file
    - Distinct groupid

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland