Another irritating (funny though) error message developers encountered while developing an ASP.NET application.

I've been caught by this error the first time and it haunted me or irritated me for few hours. Not sure what I did wrong it just happened. This usually happened to freshly deployed application to LIVE Environment if I remember it correctly.


ERROR MESSAGE:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Validation of viewstate MAC failed. If this application is hosted by a
Web Farm or cluster, ensure that < machineKey > configuration specifies
the same validationKey and validation algorithm. AutoGenerate cannot
be used in a cluster.


SOLUTION:

In web.config, inside the , add the following line:

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

L.
I am migrating a database from SQL Server 2005 to MS SQL Server 2012 and I came across this error message while running the application. (I am also upgrading the .NET Framework from 2.0 to 4.5 i know.. kind'a big jump ^_^.)

ERROR MESSAGE:
SQLException: Incorrect syntax near '*='.

I checked the stored procedure and found the culprit operator '*='. 
Obviously, I am not the initial developer of this application because I don't know what operator is that. After a minute of research, I found out that this is an operator for the LEFT JOIN and the RIGHT JOIN. But '*=' and '=*' operators syntax has been obsolete since 1992. (No wonder I haven't heard of it. I started coding around 2000.) Luckily it is still work in SQL Server 2005. 

Operator '*=' and '=*' is the LEFT JOIN and RIGHT JOIN.

SOLUTION:
So to fix this issue.. just replace to LEFT JOIN for '*=' and RIGHT JOIN for '=*'

EXAMPLE QUERY - BEFORE:

SELECT *
FROM tblPatient as A, tblInvoices as B
WHERE A.InvoiceId *= B.InvoiceId

EXAMPLE QUERY - AFTER:

SELECT *
FROM tblPatient as A LEFT JOIN tblInvoices as B 
ON A.InvoiceId = B.InvoiceId


L.


A simple way to convert or export data to a CSV format. Columns are separated by comma (a delimiter) and rows by each line. 

In my example below, I used StringBuilder for the content of my file, Environment.NewLine to move my cursor to next line. In the programming world, records can be pulled from any collections such as Dataset, LINQ and the likes. 

After the page has been executed, a .csv file will be created and a message will pop-up to ask if you want to save or open the file.


C# Code:

public void ExportCSV()
        {

            HttpContext context = HttpContext.Current;

            context.Response.Clear();
            context.Response.ContentType = "text/csv";
            context.Response.AddHeader("Content-Disposition", "attachment; filename=Result.csv");

            StringBuilder sbt = new StringBuilder();
            sbt.Append("Name,Age");
            sbt.Append(Environment.NewLine);
            sbt.Append("Anna,15");
            sbt.Append(Environment.NewLine);
            sbt.Append("Joe,12");

            context.Response.Write(csvresult);
            context.Response.End();

        }

protected void btnExport_Click(object sender, EventArgs e)
        {
           ExportCSV();
        }


L.