Welcome

Hello, Welcome to my blog. If you like feel free to refer others

Thursday 18 October 2012

'Operation is not valid due to the current state of the object' error during postback

Whenever a postback is done, this error occurs when form fields are very large in number. The stack trace is:
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) at System.Web.HttpRequest.FillInFormCollection()
By default, the maximum value of MaxHttpCollection is 1000.
To solve this error, increase the MaxHttpCollection value. Try adding the following setting in your web.config's <appsettings> block.
<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="2001" />
</appSettings>
 
It can solve your problem. If you have very large records on your page, say 600 records in a grid, and you click on Submit, then increase the value of MaxHttpCollection.
Then change value 2000 to 5000 and test again. It will be resolved. 

Question : Specifying MaxHttpCollectionKeys for a specific page - is this possible? 

No, that's not possible. It always checks the appSetting aspnet:MaxHttpCollectionKeys and if that is missing it will be set to 1000. You cannot override this because the reading of the setting and the default value is done inside an internal class.

Perhaps a better approach would be to build a form with less than 1000 items. Maybe in the form of a wizard. Or maybe by combining multiple values into a single data structure and deserializing it on the server.

for more info please visit the link

Happy learning....... :)


Tuesday 16 October 2012

Remove Duplicate Rows from a Table in SQL Server

--Create Table Script
CREATE TABLE [dbo].[ATTENDANCE](
    [AUTOID] INT IDENTITY(1,1),
    [EMPLOYEE_ID] [varchar](50) NOT NULL,
    [ATTENDANCE_DATE] [date] NOT NULL
) ON [PRIMARY] 

--Insert the into the newly created table
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
            ('A001',CONVERT(DATETIME,'01-01-11',5))
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
            ('A001',CONVERT(DATETIME,'01-01-11',5))
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
            ('A002',CONVERT(DATETIME,'01-01-11',5))
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
            ('A002',CONVERT(DATETIME,'01-01-11',5))
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
            ('A002',CONVERT(DATETIME,'01-01-11',5))
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
            ('A003',CONVERT(DATETIME,'01-01-11',5))

--Check the data from the table            
SELECT * FROM dbo.ATTENDANCE

--Check the duplicate data
SELECT * FROM dbo.ATTENDANCE WHERE AUTOID NOT IN (SELECT MIN(AUTOID)
    FROM dbo.ATTENDANCE GROUP BY EMPLOYEE_ID,ATTENDANCE_DATE) 

--Delete the duplicate data
DELETE FROM dbo.ATTENDANCE WHERE AUTOID NOT IN (SELECT MIN(AUTOID)
    FROM dbo.ATTENDANCE GROUP BY EMPLOYEE_ID,ATTENDANCE_DATE)

--Alternatively you can use the below query as well
DELETE FROM dbo.ATTENDANCE WHERE AUTOID NOT IN (SELECT MAX(AUTOID)
FROM dbo.ATTENDANCE GROUP BY EMPLOYEE_ID,ATTENDANCE_DATE)

--After deleting the duplicate data check data from the table
SELECT * FROM dbo.ATTENDANCE



So in general use the below Query-
DELETE
FROM MyTable
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM MyTable
GROUP BY DuplicateColumn1, DuplicateColumn2, DuplicateColumn3)


Table in example is has ID as Identity Column and Columns which have duplicate data are DuplicateColumn1, DuplicateColumn2 and DuplicateColumn3. 


Happy learning..... :) 

Tuesday 9 October 2012

WCF - The type name ServiceReference1 does not exist in the type Namespace.ClassName


This is a short blog post about a strange error when adding a WCF service reference. A WCF service was created and I wanted to add a service reference to a client project. I added the reference through Visual Studio and everything went fine until I compiled. Then I got this error:

Error    1    The type name 'ServiceReference1' does not exist in the type 'FeedbackCustomControl.FeedbackCustomControl'    D:\RND\ExcelApplication\FeedbackCustomControl\Service References\ServiceReference1\Reference.cs    146    46    FeedbackCustomControl


I found that this is caused by me having the same namespace name as class name (FeedbackCustomControl.FeedbackCustomControl = Namespace.ClassName). Change your namespace to a name that is not the same name as your class and this will compile.

Happy Learning..... :)