"System.OutOfMemoryException"-How to Solve?

Posted by Ganeshsvelu under C# on 4/8/2010 | Views : 9432 | Status : [Member] | Replies : 6
I want to upload mdb file that file capacity is 26MB.I Upload that one successfully after i will store that datas in sql server 2008 table.I will use storing datas for String builder & String writer.It shows "System.OutOfMemoryException".




Responses

Posted by: Vuyiswamb on: 4/8/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Add this in the webconfig between the System.web

<httpRuntime maxRequestLength="500000"/>


Thank you for posting at Dotnetfunda
[Administrator]

Ganeshsvelu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ganeshsvelu on: 4/8/2010 [Member] Starter

Up
0
Down
Now its working fine but after i stored the values in sql server 2008 table.It takes more time to store then it shows this error

"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding".

Ganeshsvelu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 4/8/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
if you use ado.net set your command object timeout to 0 that means infinite , it will not timeout.

Thank you for posting at Dotnetfunda
[Administrator]

Ganeshsvelu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ganeshsvelu on: 4/9/2010 [Member] Starter

Up
0
Down
It shows this error.

Incorrect syntax near ')'.

Ganeshsvelu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ganeshsvelu on: 4/9/2010 [Member] Starter

Up
0
Down
I Use this command.

string strCon = _connectionString;//cms.Connection.ConnectionString;
SqlConnection objCon = new SqlConnection(strCon);
objCon.Open();
SqlCommand objCom = new SqlCommand(sqlText, objCon);
objCom.ExecuteNonQuery();
objCon.Close();

Ganeshsvelu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 4/9/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Ganeshsvelu always put your code in code tags, look at the Forum guidelines. Another thing dont open the connection while you still initializing the objects. your code should look like this

string strCon = _connectionString;//cms.Connection.ConnectionString;

SqlConnection objCon = new SqlConnection(strCon);
SqlCommand objCom = new SqlCommand(sqlText, objCon);
objCom.CommandTimeout = 0;
try
{
objCon.Open();
objCom.ExecuteNonQuery();
}
catch(sqlException ex)
{

//print the ex.Message here
}
finally
{

objCon.Close();
}


look at the Bolded part its the timeout set to infinite

Thank you for posting at Dotnetfunda
[Administrator]

Ganeshsvelu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response