Friday, August 28, 2015

Recompile the store procedure to improve the performance

One of our report runs under 2min in TEST environment, but over 10 min when deployed in production.  After days of research, it turns out all we need to do is to recompile the stored procedure.

Below is from MSDN:

When a procedure is compiled for the first time or recompiled, the procedure’s query plan is optimized for the current state of the database and its objects. If a database undergoes significant changes to its data or structure, recompiling a procedure updates and optimizes the procedure’s query plan for those changes. This can improve the procedure’s processing performance.

example:
USE AdventureWorks2012;
GO
EXEC sp_recompile N'Sales.Customer';
GO

https://msdn.microsoft.com/en-us/library/ms190439.aspx

Monday, August 17, 2015

Use camelCasing JSON

Add the following code in the WebApiConfig.cs file in the App_Start folder:

In the Register static method, add:

// Web API configuration and services
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();

reference:
http://odetocode.com/blogs/scott/archive/2013/03/25/asp-net-webapi-tip-3-camelcasing-json.aspx

Wednesday, June 17, 2015

Bootstrap Themes

http://bootswatch.com/

https://wrapbootstrap.com

http://fontawesome.io/

Tuesday, June 09, 2015

MVC bootstrap Modal Dialog

starts with:  http://www.codeproject.com/Tips/826002/Bootstrap-Modal-Dialog-Loading-Content-from-MVC-Pa

Replacing Html.BeginForm with Ajax.BeginForm:  http://blogs.msmvps.com/craigber/?p=41

Fix the cache issue with Ajax.BeginForm:  http://www.leniel.net/2013/09/detecting-fixing-ajax-beginform-partial-view-stale-data.html

Monday, June 01, 2015

MVC data annotation on Password field

Below is the cheat sheet for the password field:


       
[Required]
[StringLength(255, MinimumLength=8)]
[DataType(DataType.Password)]
[RegularExpression(@"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\da-zA-Z])(.{8,15})$", ErrorMessage = "Password must contain at least 1 number, 1 uppercase letter, and 1 special character.")]
public string Password { get; set; }

 

^                   #Beginning of expression
(?=.*\d)            #At least one digit
(?=.*[a-z])         #At least one lower case
(?=.*[A-Z])         #At least one upper case
(?=.*[^\da-zA-Z])   #A non-alphanumeric character
(.{8,15})           #Allow between 8 and 15 characters
$                   #End of expression

Good website to find a starting point for Regular Expression:  http://regexlib.com/

Friday, March 23, 2012

Increase performance by adding NONCLUSTERED INDEX

Got a call from a client reporting an issue that is randomly occurred. after looking into the log file, I found one method took over a min to complete. The code shows only a simple select statement with where clause on "sentby" column. This column is a "nvarchar" and the table itself has over 1 million records.

Here is what I learned when I trying to fix this issue:

1. use "varchar" instead of "nvarchar". only use "nvarchar" when you have different languages in the same column! if you look at the sql execution plan ( sql -> display estimated ececution plan), search "nvarchar" does an index scan and "varchar" does index seek. index seek is orders of magnitude faster than a scan!

2. no index is set on "sentby" column. It won't be an issue in the small table (sql does index scan on small table), but it will impact performance when data grows. I used the script below to add a NONCLUSTERED INDEX on this column.

CREATE NONCLUSTERED INDEX IDX_MyMessageTable ON dbo.MyMessageTable
(
SentBy
)

after the index is created, the 1 min search time is down to under a second.

Tuesday, February 28, 2012

XOOM stuck on dual core logo screen (how to fix)

My XOOM was stuck on the Moto dual core logo screen last night. Soft reset (Volumn up + Power) did not work. It reboot, then still stuck on the logo screen. I searched on the web and the popular solution is to reinstall the ROM (requires android SDK and ROM at moto dev site).

This is how I fixed my issue without installing the ROM (XOOM wifi only US edition):
0. take out the microSD card if you installed one in your XOOM!!!
1. reboot (Vol up + Power)
2. On start-up when you see the Motorola logo, press and hold the Volume Down key.
3. When you see the Android recovery text, press the Volume Up key to put XOOM tablet in recovery mode. After a few min, you should see a Green Android laying down with the triangle and an exclamation (Android recovery screen).
4. On the Android recovery screen, press and keep holding the Power button then press and release the Volume Up key. This will take you to the recovery screen with list of menus.
5. Using Volume Down key navigate to Wipe data / factory reset option and press Power button to select it.
6. Select Yes, delete all user data option using Power button
7. My XOOM is fixed this way. time to set up the account again.