Monday, December 19, 2011

DateTime Functions


To get current date

SELECT GETDATE()

To get yesterday

SELECT DATEADD(d,-1,GETDATE())

Saving changes is not permitted in SQL 2008 Management Studio?



I recently started using SQL Server 2008, at first it was really nice, but then I started getting a weird error every time I tried modifying a table.

"Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created."

Row Data Bound Event and how to use it

Row Data Bound Event and how to use it :


Control Used :Grid View 
Event Under Grid View :onrowdatabound



Error 'System.Web.UI.WebControls.GridView' does not have a public property named 'SortedAscendingCellStyle'.

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Type 'System.Web.UI.WebControls.GridView' does not have a public property named 'SortedAscendingCellStyle'.

Source Error: 



Line 91: <RowStyle BackColor="White" ForeColor="#003399" />
 Line 92: <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
 Line 93: <SortedAscendingCellStyle BackColor="#EDF6F6" />
 Line 94: <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
 Line 95: <SortedDescendingCellStyle BackColor="#D6DFDF" />

Saturday, December 17, 2011

Intermittent Invalid Viewstate Error in ASP.NET Web pages

Error:
The issue presents itself with and error similar to this:
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\mdcr\5c7639a0\5981344d\App_Web_oja12imh.0.cs Line: 0 

Stack Trace: 


[FormatException: Invalid character in a Base-64 string.]
System.Convert.FromBase64String(String s) +0
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +77
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
System.Web.UI.HiddenFieldPageStatePersister.Load() +113




[ViewStateException: Invalid viewstate. 
Client IP: known ip
Port: Port number XX
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.3; .NET4.0C; .NET4.0E)
ViewState: /wEPDwUKMTY5ODYyNzkxNQ9kFgICAw9kFgICAQ9kFgJmD2QWAmYPZBYEZg9kFgICAQ88KwAJAQAPFgYeDVNlbGVjdGVkSW5kZXgCDR4IRGF0YUtleXMWAB4LXyFJdGVtQ291bnQCDmQWHGYPZBYCAgEPDxYIHghUYWJJbmRleAEAAB4EVGV4dAUMTm90aWZpY2F0aW9uHgtDb21tYW5kTmFtZQUETW92ZR4PQ29tbWFuZEFyZ3VtZW50BQEwZGQCAQ9kFgICAQ8PFggfAwEAAB8EBQkxLkNvbXBhbnkfBQUETW92ZR8GBQExZGQCAg9kFgICAQ8PFggfAwEAAB8EBRMyLlR5cGUgb2YgT3duZXJzaGlwHwUFBE1vdmUfBgUBMmRkAgMPZBYCAgEPDxYIHwMBAAAfBAUUMy5FbXBsb3ltZW50IFNvdXJjZXMfBQUETW92ZR8GBQEzZGQCBA9kFgICAQ8PFggfAwEAAB8EBRU0LlN0YXRpc3RpY3M6IEN1cnJlbnQfBQUETW92ZR8GBQE0ZGQCBQ9kFgICAQ8PFggfAwEAAB8EBRQ1LkVtcGxveWVlczogQ3VycmVudB8FBQRNb3ZlHwYFATVkZAIGD2QWAgIBDw8WCB8DAQAAHwQFFzYuU3RhdGlzdGljczogTmV3IEhpcmVzHwUFBE1vdmUfBgUBNmRkAgcPZBYCAgEPDxYIHwMBAAAfBAUZNy5TdGF0aXN...]


Cause : 
There are many reasons for this error :

  1. Web Farm or server cluster.
  2. Form Posts
  3. Application pool recycling 
  4. Proxy servers and virus scanners
Resolution :

  1. Use specific machine key in your web config. we can use these tools Link 1 or Link 2. Sample Key Node:

    <machineKey validationKey=”56AB7132992003EE87F74AE4D9675D65EED8018D3528C0B8874905B51940DEAF6B85F1D922D19AB8F69781B2326A2F978A064708822FD8C54ED74CADF8592E17″
    decryptionKey=”A69D80B92A16DFE1698DFE86D4CED630FA56D7C1661C8D05744449889B88E8DC”
    validation=”SHA1″ decryption=”AES”
    />
  2. Post to the same aspx page.
  3. Turn off the firewall and antivirus software.
  4. Adjust the settings on the application pools so that recycling is less likely to occur at peak periods.


Thursday, December 15, 2011

How to remove all asp.net data cache by c#


Introduction :
Cache feature is a great feature in asp.net. By caching we store data in memory for quick access. As Microsoft eloquently puts it, "Caching is a technique widely used in computing to increase performance by keeping frequently accessed or expensive data in memory. In the context of a Web application, caching is used to retain pages or data across HTTP requests and reuse them without the expense of recreating them."

But many times we want to update our cache for new updates to happen so to remove data cache from memory. the code snippet given below can be used to remove data cache from memory :

Method One :
foreach (DictionaryEntry dCache in HttpContext.Current.Cache)
{
   HttpContext.Current.Cache.Remove(dCache.Key.ToString());
}

Method Two :

IDictionaryEnumerator cacheEnumerator = HttpContext.Current.Cache.GetEnumerator();

while (cacheEnumerator.MoveNext())
{
  HttpContext.Current.Cache.Remove(cacheEnumerator.Key.ToString());
}

We need these two namespaces to perform this task as Generics is used

using System.Collections;
using System.Collections.Generic;


Conclusion:
These methods are used to remove data cache from memory it won't remove other cache like output or others .....

Friday, December 9, 2011

Insufficient memory error in Visual Studio 2010



“Insufficient available memory to meet the expected demands of an operation at this time, possibly due to virtual address space fragmentation. Please try again later.”


I was getting this error on my Visual Studio 2010 while copying and pasting stuff on visual studio was really annoyed by looking as visual studio takes lot of time while doing this. I tried lots and lots of ways but no good. I even tried to search on google but there was a little about this error and then i found the answer on microsoft website which had a hot fix for this bug. Scott Gu even said in his blog that this is Patch for VS 2010 Find and Replace Dialog Growing.


Title Cut or Copy displays 'insufficient memory' error in Visual Studio 2010
Release Date 6/23/2010
Size 1.65 MB
Version Hotfix
Category Build
Milestone
Description
Cut or Copy displays "insufficient memory" error in Visual Studio 2010

This is a patch from microsoft website

Download Now