Tuesday, June 30, 2009
Strong Assembly and Weak Assembly
Extension Method
This is the new feature of C# 3.0
Static method can invoke using instance method syntax.
static class contain a parameter with this key word.
E.g:
public static class NewFeature
{
public static int TointNewFeature(this int i,int j)
{
return i+j;
}
public static int TointOldFeature(int i, int j)
{
return i+j;
}
}
class App
{
static void
{
int iDemo = 2.TointNewFeature(3);
Console.WriteLine(iDemo);
iDemo = NewFeature.TointOldFeature(2,3);
Console.WriteLine(iDemo);
}
Features of Extension Method
- Contains the keyword this
- here the parameter can be leave.ie parameter should not be provided
- can be called only by an instant variable.
In ILDASM you can see system.runtime.compilerservices .extensionAttribute for the
TointNewFeature method.ie during runtime the extension is flagged and do the rest of operation.
Using Keyword in C#
When you use the using statement the Compiler automatically throws try and finally block.inside the Finally block compiler automatically cast to IDisposable inrerface and automatically calls dispose method.
Note : using can be used only which it supports IDisposable interface.So it reduce the syntax and help to dispose method automatically.reduce the number of errors.
E,g
Using(SqlConnection con = new SqlConnection())
{
…………….
}
The compailer automatically added try - finally to ‘con’ . and do the previous operation by using IDisposable.
Common Type System(CTS)
Common Type System(CTS)
Types are mechanism by which code one programming language and can be talk to different programming language.
CTS contains contains one or more member.They are fields,method,property and events
CTS also maintains access modifiers like Private,Family,Family and Assembly,Assembly,Family or assembly and public.
Note 1) CTS rules inheritance ,vrtual functions ,object life time etc.
2) CTS rules all the type must inherit from system.object.
Conclusion : Manages the type
Common Language Specification(CLS)
CLR integrates all the language and consider as same type. i.e CLR produce
self-describing type information(metadata) and a common executable environment.
Note: Some of the things we can easily write in one language not in others .CLS makes the
development easy ,i.e metada can read all other language that uses the CLR as compailer.
Conclution : Manages different languages to support.
Temporary table in SQL
Using Temporary Tables Effectively
If you do not have any option other than to use temporary tables, use them affectively. There are few steps to be taken.
- Only include the necessary columns and rows rather than using all the columns and all the data which will not make sense of using temporary tables. Always filter your data into the temporary tables.
- When creating temporary tables, do not use SELECT INTO statements, Instead of SELECT INTO statements, create the table using DDL statement and use INSERT INTO to populate the temporary table.
- After you finish the using your temporary table, delete them. This will free the tempdb resources. Temporary tables are deleted when connection is ended. but do not wait until such time.
- When creating a temporary table do not create them with a transaction. If you create it with a transaction, it will lock some system tables (syscolumns, sysindexes, syscomments). This will prevent others from executing the same query.
Monday, June 29, 2009
linked server
Linked server is used to execute command against OLEDB datasource on different server.
Advantages :
· Remote server access
· Distibuted query ,update,command and transaction on heterogeneous datasource across the enterprice.
· Ability to address diverse datasource similarity
Linked Server components :
Oledb provider and oledb datasource
Oledb provider-is a dll that manages and interact with specific
Linked server details
When a client appln execute a distributed query through a linked server ,sql server break down into command and send it to rowset and req to oledb. The row set exec and open the table from the provider.
Managing linked server Definition
To work in linked server ,register the connection formula and datasource information to sql server .After registration datasource ll always reffer to the logical name provided.
e.g
EXEC
sp_addlinkedserver @server='
@srvproduct='',
@provider='SQLNCLI',
@provstr = 'DRIVER={SQL server }; server=databasename;UID=
@datasrc='74.55.278.251'
by using proc we can add and delete the linked server
sp_addlinkedserver – to add the linked server.
Sp_linkedservers –to see the information in the linked serer.
Sp_addlinkedserver and sp_linkedservers to see more information
The tables affected are
For server details:
select * from sys.servers
For linked server Login Details :
select * from sys.linked_logins
sp_dropserver – used to delete the added server and also we can remove the remote server.
By using sql server enterprise Manager
I am not explaining this.
Identifying a Data Source Using a Linked Server Name
After registered a linked server four part name that help for the transaction.
Part Name Desc
Linked_server_name Linked server referencing the the oleDB data source
Catalog Catalog in oledb datasource Containing object
Schema Schema in the catalog contain the object
Object_name Data object in the schema
How CLR Locates and binds assemblies
Step 1: Check for the referred assembly upon the name and version.
Step 2: Check in previous referred assembly
Step 3: check in GAC
Step 4: Code base or probing
Here the information can over ride the pervious version. Here I am explaining what is happening in each step.
Step 1: Check referred assembly name and version.
· Check in the application config after the manifest check.
· Check for publishers policy (when the shared/public assembly has new version).this can be managed by
· Check in machine config(manages all .NET files in the machine)
Step 2:check in previous referred assembly
If CLR uses the same assembly it will take this only. why it is not first step means ,to examine the which version is required.
Step 3: Check in GAC (global assembly cache)
If the assembly is not found in the first two steps it should be a strong name, so it goes to GAC.
Step 4: code base or probing
This inform to CLR which version is required.
Code base: codebase is the tag in the application config .CLR checks the defined location only. if the assembly is not there probing has terminated.
Probing : if the no codebase tag is config.CLR starts probing
Subdirectories: search the application sub directories.CLR terminates probing as soon as the assembly is found.
Sunday, June 28, 2009
Portable executable(PE)
- PE Header : indicates the type of file (GUI or .dll) and it also contains time of the file created.Also contains the information of the native CPU code.
- CLR Header: Contains the information of version of managed module(PE),some flags,metadata ,the size of the metadata,strong name etc.
- Metadata: contains two tables,one contains types(eg:class used) and members defined in the source code and the second table contains members and types reffered by the source code)
- Intermediate Source Code(IL) : Compiler produce the compiled source code.the CLR then compiles the IL to native CPU instructions.
Saturday, June 27, 2009
What is Execution plan? in sql server 2005
Some of the times your proc is running slow. Because you are not looked into the execution plan.Here i explain how the execution plan is created.
Execution plan: Result of an query optimizer(that calculate the most efficient way to implement the T-sql query you submitted).By looking into this u can find out what is the problem in your query, if there is any problem.
What happens when a query is submitted?
The Query split into two stages
1) Processes that occur in relational engine.
2) Process that occur in Storage Engine.
Relational Engine
Relational engine parse the query and processed by query optimizer and produce an Execution plan.
Storage Engine
The result produce from the execution plan is sent(is a binary data) to storage engine, where data are stored and do operations like (locking, indexing transactions etc occur).
Execution plan
Execution plan is happens in relational Engine.
The following steps are happened in relational engine to produce the Execution plan.
a) Query parsing
Process: Checks the syntax
Output: Parse tree or query tree or process tree
Note: the parse tree contain the logical steps to the necessary operations for query.
If T-Sql is not a DML. So there are no opportunities to improve the performance. if T-sql is a DML So the parse tree is passing through the algebrizer.
DML: which helps developers to retrieve, insert, delete and update data in database.
Algebrizer: (process in query parsing)
Process: Resolves various name object, tables and columns.
Note: identify the each column fields (e.g.: varchar (200), int etc).It also determines the location of aggregate (group by and max etc) in the query and the process is called aggregate binding.
Algebrizer output: binary tree called query processor tree, which passed on to query optimizer.
b) Query optimizer
Which is an essential process model and says which relational engine works. Based on query processor tree and relational engine it produces the execution plan.
Cost based plan
This steps analyze which joins are used. Which calculate the cost of the execution plan, in terms of CPU.
In this step the optimizer plans which is the best plan to reduce the execution time.based on the cpu and i/o it produces the new query.
Trivial plan
If you submit a very simple query – for example, a single table with no indexes and with no aggregates or calculations within the query – then rather than spend time trying to calculate the absolute optimal plan, the optimizer will simply apply a single, trivial plan to these types of queries
Non Trivial plan
If it is a non trivial plan it performs cost based calculation. For this looks statistics maintained by sql.
Statistics: collection of data columns and indexers in data base and data distribution among them. The information for statistic is maintained by a histogram.
Histogram: tabulation of occurrence of particular values.
Plan cache: once optimizer creates execution plan this plan stored in a memory known as plan cache. if the identical plan is not there in the cache it goes to generate potential plan.
Query Execution
Once the execution plan is created it goes to storage engine and execute according to the plan.
Estimated and actual Execution plan
Two types of execution plans are there
Estimated plan: output from the query optimizer.
Actual plan: Actual query is execution.
The execution plan is stored in plan cache. The plan won’t store forever .as they aged out based on the age formula, it calculates the number of times this has been used. Lazywirter process(as garbage collector in .net) internally checks the all types of cache periodically scans the objects in the cache.
Following criteria removes the memory from the cache .
· More memory required by the system.
· The “age” plan reaches zero
· Plan is not being referred by the existing collection.
Plan can cause recompiled in the following ways
- Changing the structure or schema of a table referred by the query.
- Changing the index used by the query.
- Dropping index used by the query.
- Updating statistics used by the query.
- Calling sp_recompile
- Mixing DDL and DML .
Note: DDL (data definition language) descries the records, fields and sets makeup by the user. E.g.: create table alter table etc.