Tuesday, March 27, 2012

Operation is not valid due to the current state of the object.

Some times when using .NET web applications you have came a cross yellow pages with the stack trace some thing like bellow. 

System.InvalidOperationExceptionOperation is not valid due to the current state of the object.
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.get_Form()

Reason for this exception is a recent update which has been done to the .NET framework.  In the Microsoft security update MS11-100, they limit the maximum number of form keys to 1000 in a HTTP request. Because of this update ASP.NET applications rejects the requests which have more than 1000 of form keys. So the error message will be displayed in the browser, with HTTP 500 status code.

This change was made to address mainly the Denial of Service vulnerability. 

This new limit can be override on a per application basic by putting a new "appSettings" in an ASP.NET application’s configuration file. 

Thursday, March 22, 2012

Remove New Line charactors from data in SQL

Some times we need to avoid newline characters and other characters such as tab from the data we retrieve from the SQL server. There is a easy way to do this, we just need to replace those characters with a space or what ever we need as follows.

declare @newLine char(2)
set @newLine = char(13) + char(10)

which is in SQL :
char(9) -  Tab
char(10) - Line feed
char(13)  - Carriage return

then we can directly replace these characters when ever we need.

e.g :-
select
replace(theDataBaseField,@newLine,' ' ) 
from.....

as above we can get data without any newline characters.