OutOfMemoryException

F

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
 
S

Supra

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

can u change byte to integer or long?

regards
 
F

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top