Posts

Showing posts from June, 2014

Azure Exception after scaling

Image
System.Security.Cryptography.CryptographicException: Key not valid for use in specified state. I have recently scaled my application deployed in Azure for 2 instances. After scaling that I got the above exception when loading the application. After searching for hours I came across the solution for it. What you have to do is add the following code snippet in your configuration. < system.identityModel >    < identityConfiguration >      < securityTokenHandlers >        < add type = " System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler,                 System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 " />        < remove type = " System.IdentityModel.Tokens.SessionSecurityTokenHandler,               System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 " />      </ securityTokenHandlers >    </ identityConf...

Retrieve Sql Out parameter in c#

Recently I got an requirement of developing a Stored procedure which searches some data in our database including paging also it should return the total number of records as well. Following is the solution I came up. 1. Create a SP which returns the results set and have an output parameter in it which returns the total records count. when deciding how to get total records from the SP which has paging as well , came across with following solutions. Use COUNT(*) OVER in the select statement which will add a new column to your results set which has the total number of records as the value for each record. Create a temp table with the select statement without paging, return the results set applying paging to that results set, and out the Total count taking the total count in the temp table Use an out parameter for total ,rather creating a temp table run two separate queries and get the result set and count. after reading few articles found out 3rd option is best as it has best perfo...

Asynchronous Programming Using Delegates

Image
Delegated allow you to call any synchronous method asynchronously. In this post I will discuss way of doing this. BeginInvoke() : When a delegate is called using BeginInvoke it has same parameters as the method that you want to execute and two other parameters. AsyncCallback :delegate that references a method to be called when the asynchronous call completes Sender Object : a user-defined object that passes information into the callback method lets see how this could be done step by step. Step 1: Define delegate & call it asynchronously As the first step you can do the followings. Define a delegate with same signature as the method to be called asynchronously Assign the method to be called asynchronously to the delegate Invoke the delegate asynchronously See the sample code here: //Define a delegate with same signature as the method to be called asynchronously    private delegate void UpdateWorkLogHandler ( int hours, string workType);    static void Ma...

.net Forum June Meet up – c# events and Delegates

Image
  Hi All, Please find the .net Forum June Meet up presentation and the code samples in the below link. https://onedrive.live.com/?cid=80EDE0125C9CA03A&id=80EDE0125C9CA03A%21110 Happy Coding