solution for "Validation of viewstate MAC failed" in ASP.NET 2.0

Tuesday, August 21, 2007

If you are having a large page that uses lot of time to load and you are using built-in databound controls such as GridView, DetailsView or FormView which utilize DataKeyNames then there may be the cases whenever you perform a post back before the page loading is complete you get the follwoing error:

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]



It is an observation that whenever GridView uses DataKeyNames it requires the ViewState to be encrypted. For this, Page adds <input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" /> field just before closing of the <form> tag.

Now, if the page takes lot of time to load and you click on event then this hidden field might not bet yet rendered to the browser.

It means this field was omitted during postback, and Page doesn't "know" that viewstate is encrypted and thus causes the Exception.

A solution to this problem is to add follwoing ocde in the web.config :

<pages enableEventValidation="false" viewStateEncryptionMode ="Never" />


Exception Handling in SSIS Script Task

Wednesday, August 8, 2007

In SSIS Script Task you can use the same Structured Exception Handling (SEH) as in normal VB.NET or C# code.

Using this Structured Exception Handling you can catch specific errors as they occur and perform any appropriate action needed like letting the user know about what kind of error occurred, or logging the error or to perform some specific plan of action depending on the error.

In SSIS Script task you can Return Failure Status whenever an error is caught.

Here is an example of exception handling in Visual Basic.NET.

Public Sub Main()
Try
Dim fileContent As String
FileIO.FileSystem.ReadAllText("C:\file.txt")
Catch ex As System.IO.FileNotFoundException
Dts.TaskResult = Dts.Results.Failure
Return
End Try
Dts.TaskResult = Dts.Results.Success
End Sub


Above code tries to read the content of the file C:\file.txt and it will fail if file does not exist and throw an exception of type System.IO.FileNotFoundException. This exception will be caught in the catch block where we are returning the TaskResult as Failure. Additionally, you can perform any other action you want in this catch block.

Debug SSIS Script Component

Tuesday, August 7, 2007

While working with your SSIS package, have not you ever tried debugging a script component transformation by putting a breakpoint in the VB code? Well, i did and found that, unfortunately, it does not work.

On the other hand we are able to debug a script task using breakpoints in the same way as we do in Visual Studio IDE. But now how we go ahead with debugging a script component?

The only options to do the same are to either use the Row Count component or a Data Viewer.

Row Count task won’t be that much useful as it simply states how many rows passes through it.

On the other hand we can utilize the Data Viewer as a much better way to debug our script component. To add a Data Viewer, select the connector arrow leaving the script component that you want to debug, right click it and select Edit (you can also simply double click on that arrow). This will open up the Data Flow Path Editor. Just click on Add to add the data viewer. On the Configure Data Viewer screen, select Grid as the type. Click the Grid tab. Now you can select all those columns that you wish to see are in the Displayed Columns list. Now just close this window.

Now if you run your package, a Data Viewer window will be displayed and it will be filled with the data just after the script component is executed. This will be the data output by the Script Component. Click the Play button to continue package execution, or simply close the window. This way you can monitor all the data rows going through the script component.

I will admit that this work around of using a data viewer for debugging can never make up for the visual studio kind of debugging, but this is all we have got. We just can hope that future versions will have better debugging for a script component also as it is for the script task currently.

Followers

 

2009 ·Techy Freak by TNB