Wednesday, February 15, 2017

How to Update SQL SERVER 2012 Collation

If you have installed the SQL SERVER 2012 but had setup a different collation, here are the steps to change it:

1. Locate the install folder in the Program files. Usually it is in this folder:

C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\SQLServer2012

2.Open the Command Prompt

3. Change Directory to the one above (or where the setup is stored).

4. Run the Script below in the command prompt:

Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLCOLLATION=Latin1_General_CI_AS /SQLSYSADMINACCOUNTS=[username] /SAPWD=[Password]

5. Ensure that the [username] and [Password] are your system administrator account credentials.

6. After running the command, the SQL Server's collation is changed.

Monday, January 2, 2017

How to break when exception is thrown in C#

Sometimes during debugging an application, an unhandled exception is encountered in which we need to investigate. To find the details of this exception, we need to stop at the point of occurrence and check out the whole exception object or line of code that has a fault.
If your Visual Studio is not configured to stop on the occurrence of the exception, here is the way to turn it on:

1. Go to menu's Debug > Exceptions



2. Tick the Thrown of the CLR Exceptions

Find Control in .NET using Control ID

Here is a snippet that I have used to find a control in ASP.NET recursively:


private static Control FindControlRecursive(Control Root, string Id)
{
            if (Root.ID == Id)
            {
                return Root;
            }
            foreach (Control Ctl in Root.Controls)
            {
                Control FoundCtl = FindControlRecursive(Ctl, Id);
                if (FoundCtl != null)
                {
                    return FoundCtl;
                }
            }
            return null;
        }