Monday, June 20, 2011

Display only last charecters and replace all other digits will be by "X"

There was a request that confidential numbers should be displayed so that only last four digits are displayed and all other digits will be replaced by "X".
I planned to do it in DB and started to search a method to do it. Initially I thought I will need function but after spending some time I found that there is no need to write any function.
Following is the Query that can be used

SELECT  REPLICATE('X',LEN(AccountNo)-4)+RIGHT(RTRIM(AccountNo),4) as AccountNo,AccountNo as s from Accounts

Saturday, June 11, 2011

ASP.NET setting a time out

Many times web server take time to complete processing. Setting a time out is not that difficult. The setting is in the web.config. Normal timeout is 90 seconds. We can use timeout; it is a property of the global Server object. It is better to set it in the page init event and reset it in the page unload event.

Here is sample code


private int timeOut;
private void Page_Init(object sender, System.EventArgs e)
{
timeOut = Server.ScriptTimeout;
// SET 1 hour = 3600 seconds
Server.ScriptTimeout = 3600;
}
private void Page_Unload(object sender, System.EventArgs e)
{
Server.ScriptTimeout = timeOut;
}