Monday, February 21, 2011

Rain Again

Rain in chennai
Published with Blogger-droid v1.6.7

Monday, May 18, 2009

Tuesday, December 16, 2008

GUID VS Identity

There are some argument in favor of GUID and its mainly to maintain uniqueness in merge replication scenario or data warehousing scenario where data will be migrated from multiple servers and having single identity (INT) column will cause duplication.

Why we should not use GUID ?

1.The key issues with GUID is its very large (16 bytes) and contain alpha-numerics.

2.The key issues with GUID is its very large (16 bytes) and contain alpha-numerics. GUID’s are mainly used as PRIMARY KEY (usally CLUSTERED) to ensure uniqueness of rows.  As a rule of thumb clustered index key / primary key should be as narrow as possible (in case of primary key consider lookups for primary key column by foriegn key tables) and therefore GUID are not best suited for clustered index.

3.Again it will cause very high fragmentation and page split on data pages as well as index pages

4.client passes GUID value to be searched to database its always rendered as string and thats the last thing you want any database to do. Databases Engines are very special purpose applications and they are not very good in complicated arthmethics and string rendering and searching.

5.Optimizer always prefer to use index created on INT or numeric column as it is very easy to compare with the value (imagine comparing string with other string).

Saturday, November 15, 2008

NDepends - A Powerful Code Metrics tool

NDepends is one of the powerful tool that we have now in markt . You can get the details by visiting the following link NDepends.

A short Introduction :


NDepends is a .Net code base management tool.It mainly aims at achieving the following

things.

1.Code structure
2.Specify design rules
3.Plan massive refactoring
4.Effective code reviews
5.Master evolution

These things can b done by comparing different version of the code base.So what get's

benefitted by these things ? Well i am damn sure that one can get better productivity by

means of improved code review, easier maintenance and fast development.

Some of the features of NDepends are

1.Code Query Language (CQL)
2.Compare Builds
3.82 code metrics
4.Manage Complexity and Dependencies
5.Detect Dependency Cycles
6.Harness Test Coverage Data
7.Enforce Immutability and Purity
8.Warnings about the health of your Build Process
9.Generate custom report from your Build Process Diagrams
10.Facilities to cope with real-world environment

So how does NDepends achieves these things ?

Well the developers of NDepends derived at a idea of giving a facility so that developers can query the objects as we query in T-SQL . We can use "select * from object" or  "Select top 10 * from Object". They call them as the CQL - CODE QUERY Language.

Practical Scenario:

Lets try to create a new project in NDepends. Try downloading a Evaluation copy if you wish to try or you can purchase that from the http://www.ndepend.com.

Lets say i hav a Silverlightapplication and i want o analyze my Project now. Lets try to create a new project as follows.

A new screen

View and Hide Folders of the Assembly
Loading the project assemblies.
I have a silverlight Application and i want to analyze the code metrics. So in that case i will use th browse button to load my project file assemblies.
Run project
Similar to the Visual Studio IDE here we have a Green colored Run button . Just click that an you will get the results produced in matter of seconds. The whole result document will be produced in a Browser window. The actual code result's with the assembly details will; be there in the IDE.
You can get various informations regarding your assembly like Dependencies in a diagram format. Then the performance results like coding quality standards,design standards, unused codes, encapsulation ,test coverage, purity..
Here you can very well see a Create query button .This is th option that is used to writ the Code query language(CQL).
          Metric Results
Code Query Language
This CQL is something equal to our sql. Once you click th create query button you will get a screen like you gt for query analyzer. There you can type your queries with intellisense.
The below screen explains how you can write a query to fetch the methods that have more than 5 lines of code. Here the slider you are seeing indicates the integer value that we give for the count. Its a progress indication. You can also specify whether the method is a private or public .
The below screen shows how you can find the classes that have implemented the IDisposable interface. You can say how standard your code is and you have garbage collected well efficiently.

Conclusion:


We have lot of tools available in market for code standardization. But this tool seems amazingly great. It has given a fantastic UI and Graphical representation of the results. Particularly the Dependency diagram is amazing and so the Code metric's. One can use this in their Day to Day programming life to achieve a better productivity.

Friday, November 7, 2008

Sql Transaction Isolation Level

Controls the locking and row versioning behavior of Transact-SQL statements issued by a connection to SQL Server.

SET TRANSACTION ISOLATION LEVEL
{ READ UNCOMMITTED
| READ COMMITTED
| REPEATABLE READ
| SNAPSHOT
| SERIALIZABLE
}
[ ; ]

READ UNCOMMITTED
Specifies that statements can read rows that have been modified by other transactions but not yet committed.

READ COMMITTED
Specifies that statements cannot read data that has been modified but not committed by other transactions. This prevents dirty reads.

REPEATABLE READ
Specifies that statements cannot read data that has been modified but not yet committed by other transactions and that no other transactions can modify data that has been read by the current transaction until the current transaction completes.

SNAPSHOT
Specifies that data read by any statement in a transaction will be the transactionally consistent version of the data that existed at the start of the transaction.

SERIALIZABLE

Specifies the following:

* Statements cannot read data that has been modified but not yet committed by other transactions.
* No other transactions can modify data that has been read by the current transaction until the current transaction completes.
* Other transactions cannot insert new rows with key values that would fall in the range of keys read by any statements in the current transaction until the current transaction completes.

Tuesday, October 21, 2008

Silverlight With Entity Framework & Ado.Net Data Service

Silverlight 2 is released. Achieving a database connectivity with the silverlight through a Ado.Net data service seems quite

complicated while trying initially. I have tried a lot and at last trie to achive the connectivity. I have followed the

following steps to achive this.

1. Create a blank new silverlight project with Asp.net website enabled.
2. Add a new entity model (SchoolModel) referring your database for example say School Database. For this a new schoolEntity

will be generated.
3. Add a new Ado.Net data service say ScDataSRC.svc. There specify the context name of your service as SchoolEntity.

Public Class ScdDataSrc
Inherits DataService(Of SchoolEntities1)

4.Set the web properties of the webapplication so that it runs in a standrad port instead of dynamic configuration.

5.Now test the service by setting the service as the startup page ScDataSrc.svc . you will get a url like
http://localhost:2031/ScdDataSrc.svc/

6.Now in the silverligh project just refer this service.
Take for example we are going to fill a datagrid in the silverlight page. Add them in the XAML.




7. Import the following in the Silverlight application

Imports Microsoft
Imports System.Data.Services.Client
Imports SilverlightApplication6.SchoolRef

8. Silverlight deals the data in an Asynchronous way. So we have to handle them in th following way

1. Create a instance for the context
Dim ctx As New SchoolRef.SchoolEntities(New Uri("http://localhost:2031/ScdDataSrc.svc/"))

2. form the linq query that needs to fetch the data.

Dim pr = From c As Course In ctx.Course _
Select c

3. Now typecast the query to dataservice query and assign a asynchronous method to that . This asynhronous
method takes care of fetching the data from service .
Dim prdquery As DataServiceQuery(Of Course) = DirectCast(pr, DataServiceQuery(Of Course))
prdquery.BeginExecute(New AsyncCallback(AddressOf onLoadComplete), prdquery)

Public Sub onLoadComplete(ByVal result As IAsyncResult)
Dim results As IEnumerable(Of Course)
results = DirectCast(result.AsyncState, DataServiceQuery(Of Course)).EndExecute(result)
Me.MyCombo.DataContext = results.ToList


4. Bind the objects inside the Async methods.


Thursday, October 9, 2008

Partial PostBacks with ICallbackEventHandler

Icallbackeventhandler is one of the Interfaces provided by Microsoft for enabling Partial postbacks in pages .This can be used in situations where we cannot use the UpdatePanels this seems to be very useful.
for example i have a situation where two control's are dynamically created . one is a link button and another is a span control just to display some warnings. When the link button is clicked some actions occur in the server and the warnings of that action are displayed in the span control. Here i could not use the update panel's since the controls are dynamically created and they are not in same position . They are in some parts of

the page.
Here comes the rescue in the form of the ICallbackEventhandler !.

We can do the partial postback Synchronous and Asynchronous. Here i have explained the Synchronous way of doing that . We can achieve this Asynchrnously by means of IAsync. I will discuss about this in another post.

We have to implement this interface ICallbackEventhandler in the page class.
Partial Class EditClass
Inherits System.Web.UI.Page
Implements ICallbackEventHandler

Once we implement we get these methods GetCallbackResult() and RaiseCallbackEvent(ByVal eventArgument As String) implemented.

We have a set of JavaScript functions to be defined for using this Icallbackeventhandler. They are
1.The function to be called from the control from client side.
This is the function that is called from the control which needs the partial postback.


Here we are using a asp.net server control. So we are calling a javascript funtion from the onClientClick.This function has to be written in the page's markup as follows.


function CallServer() {
var justExample = '';
MakePostBack(justExample,'');
}

2.The functions that are generated from the code Behind files. They are as follows
Dim cs As ClientScriptManager = Page.ClientScript
Dim cbref As String = cs.GetCallbackEventReference(Me, "arg", "ReceiveServerData", "context")
Dim cbscr As String = "function MakePostBack(arg, context){" + cbref + ";}"
cs.RegisterClientScriptBlock(Me.GetType(), "MakePost", cbscr, True)

We are getting the callback reference of the page from this method GetCallbackEventReference. This will get generated something like "WebForm_DoCallback
('__Page',arg,ShowPop,context,null,false);". We make this call in another javascript function to make this postback call. This we make by means of the registering hte script to the page's clientscriptmanager.

3. The server methods GetCallbackResult() and RaiseCallbackEvent(ByVal eventArgument As String) have to be defined.

Define this string _str in page level
Dim _str As String

'This function returns the data to the client
Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Return _str
End Function

'This is the Callback function from the control. Here we can do the needed manipulation with the arguments which we receive from the client page.
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
_str="Hello World"
End Sub

4. Then we have to define the function ReceiveServerData in Markup page. This is the function that receives the data from the server. We can use this for our specific needs. You can even get a full data

source by means of the XML string's and manipulating in the client side XMLDom javascript objects.

function ReceiveServerData(result, context) {

var strResult = new String();
strResult = result;
alert(strResult );
}

I have referred the following Microsoft Article to be very very useful for this .