Posts

Showing posts from 2013

Get Sql Azure DB size in GB

SELECT sum ( reserved_page_count ) * 8.0 / 1024 / 1000       FROM sys . dm_db_partition_stats

Query Azure WADLogsTable

Image
  When you have Azure WADLogTable loaded with tons of records, queries takes longer time to return results by using TimeStamp.   WADLog Table index by partition key and if I query by partition key I see logs are returning way faster. Partition key is datetime in ticks, you can get datetime in ticks by converting datetime string into ticks. I’m lazy to open VS just to get datetime in ticks and use LINQPad tool for these kind of quick conversions. It’s kind of opening notepad and writing C# statements. Code to get datetime in Ticks:   DateTime dt = new DateTime( 2013 , 08 , 29, 0,0,0 ); long l = dt.Ticks;  Console.WriteLine(l); //gives 635133312000000000   Once you have datetime string in ticks prefix 0 , use that value to query the table & you can start see logs immediately.   Query to Table – PartitionKey gt '0635133312000000000' If you want to see errors in log file use query with level = 2.  PartitionKey gt '06

How to do UnitTest (Database Test) SQL Server with Visual Studio 2012

http://msdn.microsoft.com/en-US/library/bb381703(v=VS.80).aspx http://sqlwithsanil.com/2012/07/08/database-unit-testing-made-easy-with-visual-studio-team-systems/ http://weblogs.asp.net/gunnarpeipman/archive/2013/02/07/using-database-unit-tests-in-visual-studio.aspx

Azure Scenario based examples

http://www.windowsazure.com/en-us/develop/net/end-to-end-Apps/

EF FK Relation Errors

http://mocella.blogspot.com/2010/01/entity-framework-v4-object-graph.html

Find Date gap between SQL rows

DECLARE @Table TABLE (        Id                    INT IDENTITY ( 1 , 1 ),        Idn                   INT ,        StartDate             DATE ,        EndDate               DATE )   INSERT INTO @Table SELECT 1 , '2013-07-01' , '2014-06-30' UNION SELECT 1 , '2014-07-01' , '2015-06-30' UNION SELECT 1 , '2015-07-10' , '2016-06-30' UNION SELECT 1 , '2016-07-05' , '2017-06-30' Select * From @Table   ; WITH CTE AS (        SELECT *, ROW_NUMBER () OVER ( PARTITION BY Idn ORDER BY StartDate ) rownumber        FROM    @Table ) SELECT A . Id , A . Idn , A . StartDate , A . EndDate , B . StartDate AS NextStartDate , DATEDIFF ( D , A . EndDate , B . StartDate )   AS Gap FROM    CTE AS A JOIN CTE AS B ON B . Idn = A . Idn AND B . RowNumber = A . RowNumber + 1 WHERE   DATEDIFF ( D , A . EndDate , B . StartDate ) > 1

How to Capture StoredProcedure Errors into Application

Recently I have been working on data access layer and wondering how to capture raise errors of stored procedure. I realized we can't capture stored procedure error if dataset being used in application. In order to capture stored procedure error, application should use Data Reader instead of Data Adapter. Ref: http://support.microsoft.com/kb/811482 Thanks, -Venu.

Basic steps to develop mobile App

http://www.asp.net/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application

Authenticate User using FaceBook/Google using OpenAuth

http://blogs.msdn.com/b/webdev/archive/2012/09/12/integrate-openauth-openid-with-your-existing-asp-net-application-using-universal-providers.aspx http://blogs.msdn.com/b/webdev/archive/2012/08/22/extra-information-from-oauth-openid-provider.aspx

WCF REST Client Console App

The following is the console client, which consumes Rest Service:   using System.Net; using System.IO;   static void RestCall()         {             string baseUri = http://localhost:33987/MyService.svc/GetData/10 ;             HttpWebRequest req = WebRequest .Create(baseUri) as HttpWebRequest ;             HttpWebResponse resp = req.GetResponse() as HttpWebResponse ;             var response = resp.GetResponseStream();             try             {                 StreamReader streamReader = new StreamReader (response, true );                 try                 {                     var target = streamReader.ReadToEnd();                     Console .WriteLine(target);                 }                 finally                 {                     streamReader.Close();                 }             }             finally             {                 response.Close();             }         } App.Config Entries:

WCF REST 400 Bad Request

Today while I was writing my WCF Rest Client, I was getting error as "400 Bad Request". Finally I realized the culprit of error was service name in web.config file. In order to resolve this error, make sure service name is matching with your service markup's service name. If you have servicename1.svc, right click on that file and select "View MarkUp". Copy Service value from that and paste it into webconfig's services service name. Service1.svc MarkUp: <% @ ServiceHost Language ="C#" Debug ="true" Service ="MyServiceNameSpace.Service1" CodeBehind ="Service1.svc.cs" %> Web.config Services Section: < services >    < service name = " MyServiceNameSpace.Service1 " >      < endpoint address = "" behaviorConfiguration = " restService "            contract = " MyServiceNameSpace.IService1 " binding = &