473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

OutOfMemoryException

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.Connecti onObject.sConnection_Strin
g)
dbConn.Open()

dbTrans =
dbConn.BeginTransaction(IsolationLevel.Serializabl e)
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

Nov 20 '05 #1
4 2189
i had same problem while i was doing picture puzzle using vb.net window.

can u change byte to integer or long?

regards

Fredrik Melin wrote:
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.Connecti onObject.sConnection_Strin
g)
dbConn.Open()

dbTrans =
dbConn.BeginTransaction(IsolationLevel.Serializabl e)
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


Nov 20 '05 #2
Problem is that fileStream dont like integer or long...

Strange:

Dim b(16773738) As Byte does NOT work

Dim b(17773738) As Byte WORKS!

"Supra" <su*******@rogers.com> wrote in message
news:qD***************@news04.bloor.is.net.cable.r ogers.com...
i had same problem while i was doing picture puzzle using vb.net window.

can u change byte to integer or long?

regards

Fredrik Melin wrote:
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.Connecti onObject.sConnection_Strin g)
dbConn.Open()

dbTrans =
dbConn.BeginTransaction(IsolationLevel.Serializabl e)
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

Nov 20 '05 #3
Ah....

http://support.microsoft.com/?kbid=826981
"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
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.Connecti onObject.sConnection_Strin g)
dbConn.Open()

dbTrans =
dbConn.BeginTransaction(IsolationLevel.Serializabl e)
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

Nov 20 '05 #4
good for u.
i used to too that b4.
regards,

Fredrik Melin wrote:
Ah....

http://support.microsoft.com/?kbid=826981
"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
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.Connecti onObject.sConnection_Strin
g)
dbConn.Open()

dbTrans =
dbConn.BeginTransaction(IsolationLevel.Serializa ble)
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



Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peter Aberline | last post by:
Hi all, We have written a C # .NET application and we're encountering memory problems in the form of System.OutOfMemoryException. Our application creates many thousands of objects in a...
4
by: Ryan Seghers | last post by:
I've got a program that has no user interface (like a service but not actually a Windows Service yet) in which I'd like to handle OutOfMemoryExceptions. I'd at least like to log the failure before...
0
by: Per Bergland | last post by:
After many woes, I finally managed to get a stack dump of my System Service (written in C#) that insists on crashing when launched at system boot time (see below on how to get this dump - I...
3
by: Michael | last post by:
I have a problem with catching the OutOfMemoryException in a managed C+ application. When creating small objects on the managed heap neithe the catch handler for OutOfMemoryException nor the...
1
by: Ripul Handa | last post by:
Hi We are running IIS 5.0 cluster with cisco local director. We are running a website on 2 webservers and I have been observing that from past few days we have are getting this error message of...
1
by: SMG - Idealake | last post by:
Hi all, I am getting following error on my error, what could be the reason? Exception of type System.OutOfMemoryException was thrown. Description: An unhandled exception occurred during the...
2
by: Dave | last post by:
We just started getting this error message in our application today (stack trace below). From the OutOfMemoryException, I'm guessing it could be a memory leak. I'm making sure I'm closing all my...
1
by: Ashkan Daie | last post by:
Hi All, When trying to install a performance counter via InstallUtil I get the following exception: Creating performance counter category Enterprise Library Caching. An exception occurred...
13
by: Venkatachalam | last post by:
Hi, In my application I have text(flat) file as input and I have to generate an XML file. The maximum input text file size can be 900MB and gererated xml may result 2+ GB. Based on the first...
8
by: =?Utf-8?B?UGlnZ3k=?= | last post by:
Hi to all, I am getting this System.OutOfMemoryException calling the Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(<stream>,<Obj>) method. The type of <streamis...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.