Tuesday, November 23, 2004

Canonicalization

What is Canonicalization?

Canonicalization is the process by which various equivalent forms of a name can be resolved to a single standard name, or the "canonical" name. For example, on a specific computer, the names c:\dir\test.dat, test.dat, and ..\..\test.dat might all refer to the same file. Canonicalization is the process by which such names are mapped to a name that is similar to c:\dir\test.dat.

When a URL is received by a Web server, the server maps the request to a file system path that determines the response. The canonicalization routine that is used to map the request must correctly parse the URL to avoid serving or processing unexpected content.



This issue affects Web content owners who are running any version of ASP.NET on Microsoft Windows 2000, Windows 2000 Server, Windows XP Professional, and Windows Server 2003.

To know more about this issue and recommended guidance on best practices visit

http://www.microsoft.com/security/incident/aspnet.mspx

Wonder why GC has only 2 generations

The CLR Garbage Collector is a generational, mark-and-compact collector. It follows several principles that allow it to achieve excellent performance. First, there is the notion that objects that are short-lived tend to be smaller and are accessed often. The GC divides the allocation graph into several sub-graphs, called generations, which allow it to spend as little time collecting as possible. Gen 0 contains young, frequently used objects. This also tends to be the smallest, and takes about 10 milliseconds to collect. Since the GC can ignore the other generations during this collection, it provides much higher performance. G1 and G2 are for larger, older objects and are collected less frequently. When a G1 collection occurs, G0 is also collected. A G2 collection is a full collection, and is the only time the GC traverses the entire graph. It also makes intelligent use of the CPU caches, which can tune the memory subsystem for the specific processor on which it runs. This is an optimization not easily available in native allocation, and can help your application improve performance.

What Happens When a Collection Occurs?

Let's walk through the steps a garbage collector takes during a collection. The GC maintains a list of roots, which point into the GC heap. If an object is live, there is a root to its location in the heap. Objects in the heap can also point to each other. This graph of pointers is what the GC must search through to free up space. The order of events is as follows:

1. The managed heap keeps all of its allocation space in a contiguous block, and when this block is smaller than the amount requested, the GC is called.
2. The GC follows each root and all the pointers that follow, maintaining a list of the objects that are not reachable.
3. Every object not reachable from any root is considered collectable, and is marked for collection.

4. Removing objects from the reachability graph makes most objects collectable. However, some resources need to be handled specially. When you define an object, you have the option of writing a Dispose() method or a Finalize() method (or both). I'll talk about the differences between the two, and when to use them later.
5. The final step in a collection is the compaction phase. All the objects that are in use are moved into a contiguous block, and all pointers and roots are updated.
6. By compacting the live objects and updating the start address of the free space, the GC maintains that all free space is contiguous. If there is enough space to allocate the object, the GC returns control to the program. If not, it raises an OutOfmemoryException


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

OLAP Queries in .NET

This article Querying an OLAP datasource with C# shows how we can handle MDX queries with ADO.NET. This is achieved using ADOMD (Multi-dimensional) 2.7 with a runtime callable wrapper.

Its worth a read..

http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=640

I wonder if Microsoft has any plans to introduce managed provider for OLAP. That would be great!

To know more about MDX Query of SQL Server Analysis Services visit

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/olapdmad/agmdxbasics_0v7d.asp


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

How .NET generics work?

This white paper explains clearly on the working of .NET Generics

http://research.microsoft.com/projects/clrgen/generics.pdf

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Creating Windows Service in .NET Framework

Windows services are applications that run outside of any particular user context in Windows NT, Windows 2000, or Windows XP. The creation of services used to require expert coding skills and generally required C or C++. Visual Studio .NET now makes it easy for you to create a Windows service, whether you're writing code in C++, C#, or Visual Basic. You can also write a Windows service in any other language that targets the common language runtime. This article walks you through the creation of a useful Windows service, then demonstrates how to install, test, and debug the service.

http://msdn.microsoft.com/msdnmag/issues/01/12/NETServ/default.aspx


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Saturday, October 23, 2004

Redirecting assembly versions

When you build a .NET Framework application against a specific version of a strong-named assembly, the application uses that version of the assembly at run time. However, sometimes you might want the application to run against a newer version of an assembly. An application configuration file, machine configuration file, or a publisher policy file can redirect one version of an assembly to another.

more details are here http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconassemblyversionredirection.asp



With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Application Restore Utility

In v1.0/v1.1 of the CLR, there is a relatively obscure feature known as the .NET application restore tool. This feature makes use of log files which record binding information when running a managed app. The idea is that if binding policy for your application changed, the tool would be able to analyze this data, and generate an app.exe.config file, which can get you back to binding settings you used previously.

To know more about .NET Application Restore Tool navigate to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingnetapplicationrestoretool.asp


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Activator.CreateInstance() Method

Activator is a class in System namespace...

This class is one of the most widely used class to create instances at runtime, of types locally or remotely defined...

Usually it returns back an object or an objecthandle...
There are lots of overloads of this method and in local scenarios mostly take System.Type() as one of the parameter...

Its certain overloads also take typename as string and return back an object handle...
This objecthandle then needs to be unwrapped to get back the object...
The overload which returns objecthandle is mostly used in Remoting...

CreateInstance is a static member of the class and so can be accessed directly without object creation...

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Build Vs Rebuild in VS.Net

A very basic but a less know question for today...

What is the difference between Build and Rebuild solution in VS.Net or why at all we have two...

Well the difference is that Build solution will build only those projects which are changed since the last build... It will not get the changes of the updated embedded resource files...

Rebuild soultion will cause everything to be rebuilt no matter whether it was changed or not...

If you are making small projects the differences would not matter much but for large builds these are really useful...

There are advanced differences though but these are something which all should know...

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Tuesday, September 28, 2004

How to prevent memory leak in C#.NET?


If you are letting .NET to manage memory, it will do a good job of memory management. If you start messing with the GC then you get into big trouble.

.NET's GC does not collect items right away, it lingers around in case the block is needed somewhere else. It collects when it thinks it should.

Don't mess with memory management unless you have a really, really good reason to. The Dispose method is used to release unmanaged resources that aren't handled by the garbage collector, like some streams and graphics operations. If you are using these, then you'll want to call the Dispose method when you're done with the object. The object itself will remain in memory until it's collected, but the unmanaged resources associated with it will be freed.

Note: For most streams, the Dispose method will probably be replaced by the Close method, which does the same thing.



With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Delegate: A neat example!

Delegate: A neat example!

Suppose your daughter is grounded: she's not allowed to use the phone.
If she picks up the phone, both mom and dad want to know about it.

Slap this code on her and she could wind up in big trouble!


using System;

namespace Grounded {

class Mother {

public void subscribe() {

Console.WriteLine("Mother Subscribing");

Daughter.onPhoneCall += new Daughter.OnPhoneCallHandler(Notify);

}

public void Unsubscribe() {

Console.WriteLine("Mother Unsubscribing");

Daughter.onPhoneCall -= new Daughter.OnPhoneCallHandler(Notify);

}

public void Notify() {

Console.WriteLine("Mother Notified");

}

}

class Father {

public void subscribe() {

Console.WriteLine("Father Subscribing");

Daughter.onPhoneCall += new Daughter.OnPhoneCallHandler(Notify);

}

public void Unsubscribe() {

Console.WriteLine("Father Unsubscribing");

Daughter.onPhoneCall -= new Daughter.OnPhoneCallHandler(Notify);

}

public void Notify() {

Console.WriteLine("Father Notified");

}

}


class Daughter {

public delegate void OnPhoneCallHandler();

public static event OnPhoneCallHandler onPhoneCall;

public void PlaceCall() {

Console.WriteLine("Daughter placed call");

if(onPhoneCall != null) {

onPhoneCall();

}

}

}


class Class1 {

static void Main(string[] args) {

Father f = new Father();

Mother m = new Mother();

Daughter d = new Daughter();

m.subscribe();

f.subscribe();

d.PlaceCall();

m.Unsubscribe();

f.Unsubscribe();

d.PlaceCall();

}

}

}

Tuesday, September 21, 2004

Xcopy Deployment

Xcopy command is used to easily copy all the files of a .Net application to
a target installation directory... For applications that do not require any
further registration Xcopy is command is the simplest way to distribute your
.Net applications...

Do note that Xcopy command does not copy the hidden and system files... Also
note that Xcopy creates files with the archive attribute set, whether or not
this attribute was set in the source file...If you have a disk that contains
files in subdirectories and you want to copy it to a disk that has a
different format, you should use the Xcopy command instead of Diskcopy.
Since the Diskcopy command copies disks track by track, it requires that
your source and destination disks have the same format. Xcopy has no such
requirement. In general, use Xcopy unless you need a complete disk image
copy or you wish to copy the system files.

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

App Config File not being picked up

Some times you would have done nearly everything right in the windows
application but still on trying to access configuration file you would get
back null or nothing... Well the problem might be the name that you have
used for the config file...

You should know that for a windows based application to pick up app.config
file following should be taken care of...
1.) The app.config name should match your assembly name... i.e. if you have
myassembly.dll then the config file name should be myassembly.config...

2.) Also you should know that the config file is picked up for the main or
the application which is the starting point... So your app.config file
should be attached to that...


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

When using the SqlDataReader, how can I tell how many records where found?

When using the SqlDataReader, how can I tell how many records where found?

The SqlDataReader provides a means of reading a "forward-only" stream of rows from a SQL Server database. Hence the number of rows read from the database is not known until the last row is read.

This is the same type of problem we had back in classic ADO where the Recordset's RecordCount was always -1 for a server-side, forward-only cursor. The solution in classic ADO was to use a static or keyset cursor. Or use a client-side cursor location, which always used a static cursor. However in ADO.NET 1.0, there is no such thing as a server-side, static or keyset cursor. There is only the server-side, forward-only DataReader. Or there is the client-side, static DataSet (in classic ADO "terms").

You can work-around this issue by either

1) Increment a counter while looping throuh all of the rows, or

2) use two SELECT statements in your query. The first one returns the row count and the second one returns the actual rows. e.g. "SELECT COUNT(*) FROM myTableName; SELECT * FROM myTableName". Then you can use the NextResult method to move from the first to the second result set, or

3) Or use a DataSet instead of the SqlDataReader. Then use the DataSet's Table Rows count. e.g. oDataSet.Tables("Products").Rows.Count

For more information, see: http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q308050

#) Best Practices for Using ADO.NET
Learn about the best solutions for implementing and achieving optimal performance, scalability, and functionality in Microsoft ADO.NET applications


* Information about the .NET Framework data providers included with the .NET Framework.
* Comparisons between the DataSet and the DataReader, and an explanation of the best use for each of these objects.
* An explanation on how to use the DataSet, Commands, and Connections.
* Information about integrating with XML.
* General tips and issues.

more here..http://msdn.microsoft.com/library/defaultasp?url=/library/en-us/dnadonet/html/adonetbest.asp

#) What is the difference between a Recordset and Dataset?

A Recordset is a single set of data from a database, whereas a DataSet is a relational set of data. ADO.NET allows for DataSets to be populated from the database, but DataSets are not exclusively an ADO.NET construct. A single dataset may house related, but distinct sets of data. For example, a dataset may contain a table of information about a patient (think a patient recordset) and also a related table of all the medications the patient is taking. In ADO, you would need to treat these as different recordsets. In ADO.NET this is remarkably different. DataSets are also inherited as disconnected.


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Obtaining installation state of Visual Studio .NET programmaticall

The following article describes how to obtain the installation state of Visual
Studio .NET programmatically.

Typically, you can examine a file or a registry entry to determine
whether you have a version of Microsoft Visual Studio .NET, or of any
program, already installed on your computer. You can also determine
the version information programmatically by using Microsoft Windows
Installer functions such as the MsiQueryProductState function. The
MsiQueryProductState function takes the product code as the input
parameter and then returns the installation state of the program.


http://support.microsoft.com/default.aspx?scid=kb;EN-US;884468


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Friday, August 27, 2004

Pre-defined Visual Studio Command Aliases

A list of Visual Studio pre-defined commands

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxgrfpredefinedcommandlinealiases.asp


With Best Regards
Mitesh Mehta

Monday, August 23, 2004

Reading Text file with XML DOM object

Hi,
XML DOM has no limitations on the kind of file it can open, what is important is that the content be XML. In your case, for this document to be a valid XML Document, the root node is missing. So, you would have a two step process for processing this doc as XML DOM.
1. Using XML Dom, create the root node and read the TXT file into a filestream
2. Concat the TXT file to the root node created above.

Now coming to the caveats of DOM.
Remember, DOM creates a tree in mem. This tree is so huge that its nearly 10 times the size of the original doc, once in memory.
Secondly, DOM is slower any day to actual raw file processing i.e. using streams. FSO is a different story. For that the VBScript engine has to be loaded, and then the file loaded (Unless of course you are referring to a VBScript here :) )

My suggestion would be, load the file into the FSO as you are doing now, and use the RegularExpression object (available in both, .NET as well as VBScript 5.0 onwards) to select the text between the and tags. Don't go for DOM unless you are looking at some requirement in the future which might need this doc available for XML processing.

With Best Regards,
Mitesh V. Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Thursday, August 19, 2004

Transaction

Transactions in .Net

We talked about Transactions in .Net a few days back... We learnt that how
they can be automatic or manual...Now ,we will talk about Automatic
Transactions this whole week... Hopefully it will be interesting and
useful...

Automatic Transaction manages transaction boundaries for you... But again it
manages the boundaries on the basis of what you suggest it to do (you do
that by attributes which we will talk in a couple of days... ) The
transaction flows from one object to other as instructed... Within its
scope, it includes, the objects that are suppose to participate in
transactions and leaves out the objects that are not suppose to
participate...

Note: Nested transactions are not possible in Automatic model...

---------xxxxxx--------------------
Transaction Attribute for your class

We discussed that for our class to participate in transactions we need to do
certain things... Now we will talk about what those certain things have to
be...

One of the things that you need to do is to apply Transaction attribute to
your class... You would apply it just before your class declaration... It
would look something like:

[Transaction(TransactionOption.Supported)]

Now if you are familiar with COM+ transactions then TransactionOption has
values which are very similar to COM+ transaction options...

The TransactionOption values can be Disabled, NotSupported, Supported,
Required, RequiresNew... Out of these Required is the default...



With Best Regards
Mitesh Mehta
eMAIL : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta

Wednesday, August 11, 2004

Changing Reference to different version of external assembly










Changing Reference to different version of external assembly

Consider a scenario when your application is referencing version 1.0.1.1 of
"SomeAssembly" in GAC... Now you realize that there are some major bugs in
that assembly and you want your assembly to reference the new version of the
assembly (say 1.0.2.0) and you do not want to go ahead and recompile your
code for that... What would you do... Well here is the answer... You would
go and change the configuration file with similar updates to the ones I am
writing below...

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asmv1">
<publisherPolicy apply="no"/>
<dependantAssembly>
<assemblyIdentity name="SomeAssembly"
publicKeyToken="whatever" />
<publisherPolicy apply="no"/>
<bindingRedirect oldVersion="1.0.1.1"
newVersion="1.0.2.0" />
</dependantAssembly>
</assemblyBinding>
</runtime>
</configuration>
Regards,
Mitesh v. Mehta

Snippet Compiler


Snippet Compiler










Snippet Compiler Here are its
features:



  • Compiles and runs single or multiple C#, VB.NET
    and ASP.NET snippets.

  • Optionally builds WinForm EXEs, console
    EXEs or DLLs.

  • The user can store a library of
    templates.

  • Displays compile errors and warning, including
    wave lines in editor with error/warning tooltips.

  • IntelliSense for static members and method
    signatures, as well as constructor signatures.

  • Imports VS.NET projects.
  • Conveniently sits in the notification
    area waiting to be useful.

  • Exports snippets to HTML/RTF.

Regards,
Mitesh v. Mehta


Common Type System - Value Types vs Reference Types










Common Type System - Value Types vs Reference Types

Value Types and Reference Types are two basic types of CTS... Value Types
are allocated on the stack and Reference Types are allocated on Managed
heap... How this thing work is that the value of the "Value Types" is
allocated on the stack where as in case of "Reference Types" the value i.e.
the object itself resides in the heap but there is a pointer to the object
in the memory...

Considering this differences value types are faster but consume the process
memory.... Managed type don't consume this process memory but then they
become slower... When value types are copied then the whole object is copied
on the heap, when reference types are copied then only the reference is
copied... Inshort, there are pros and cons to both and sometimes you have an
option to choose one of them in your development sometimes you don't
have....

Value types are usually native data types like int, float, string, char,
enums etc... Reference types mostly include classes and some other user
defined types...
Regards,
Mitesh v. Mehta



.NET Supporting Languages List...


.NET Supporting Languages List...









.NET Supporting Languages List...

Language Company URL
Perl ActiveState www.activestate.com/visualperl/
Python ActiveState www.activestate.com/visualpython/
RPG ASNA www.asna.com/avr_caviar_information.asp
APL Dyadic Systems www.dyadic.com/msnet.htm
Oberon ETH Zentrum www.oberon.ethz.ch/oberon.net/
Cobol Fujitsu www.adtools.com/dotnet/index.html
Fortran Fujitsu www.fs.fujitsu.com/products/fortran.html
Eiffel ISE dotnet.eiffel.com
Haskel Massey University www.mondrian-script.org
Mondrian Massey University www.mondrian-script.org
J# Microsoft msdn.microsoft.com/visualj/jsharp/beta.asp
Standard ML Microsoft Research research.microsoft.com/projects/sml.net
Scheme Northwestern University rover.cs.nwu.edu/~scheme/
Pascal QUT www.plasrc.qut.edu.au/ComponentPascal/
Fortran Salford Software www.salfordsoftware.co.uk/compilers/ftn95/dotnet.shtml
SmallScript SmallScript www.smallscript.net
SmallTalk SmallScript www.smallscript.net
Pascal TMT Development www.tmt.com/net/
Mercury University of Melbourne www.cs.mu.oz.au/mercury/dotnet.html

Regards,
Mitesh v. Mehta

Ensuring a single instance of your .Net application


Ensuring a single instance of your .Net application









[STAThread]
static void Main()
{
bool ok;
m = new System.Threading.Mutex(true, "YourNameHere", out ok);
if (! ok)
{
MessageBox.Show("Another instance is already running.");
return;
}
Application.Run(new Form1());
GC.KeepAlive(m);
}
Regards,
Mitesh Mehta
http://cc.1asphost.com/miteshvmehta/

Know about Data Protection API (DPAPI)


Know about Data Protection API (DPAPI)









What is the Data Protection API? The DPAPI is used to hide secrets like
connection strings and user credentials that are typically stored in a
config file. Instead of storing the plain text, you can use DPAPI to encrypt
and decrypt the secrets at a machine or user specific level.

Read and learn more at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsecure/html/windataprotection-dpapi.asp
Regards,
Mitesh v. Mehta



Network Ports Used by Key Microsoft Server Products.


Network Ports Used by Key Microsoft Server Products.









I found this nice link from http://www.only4gurus.com/ which also gives one .pdf files containing the list of Network Ports Used by Key Microsoft Server Products and their explaination.
Thanks and Regards,
Mitesh V. Mehta

KnowledgeBase: Remoting at a Glance.


KnowledgeBase: Remoting at a Glance.









Remoting at a Glance.

An
end-to-end picture of remoting is as follows. The host application is
loaded and registers a channel and port on which to listen for incoming
calls. The configuration file, if any, is read and an object’s remoting
information is loaded—the host application can now map a URI to the
physical assembly and instantiate the object when required. The client
application also registers the same channel and then attempts to create
a new instance of the remote class. The remoting system handles the
request for a new instance by providing a proxy object in place of the
actual object on the server. The actual object is either created
immediately for CAOs or on the first method call for Singleton/Singlecall objects—the
remoting framework takes care of this for you automatically. When the
client calls a method on the proxy object, the information is sent
across the channel to the remote object. The remoting system will then
pass back the results of the method across the channel in the same
manner

- C# .NET - Web Developers Guide

Regards,
Mitesh v. Mehta


Tuesday, July 27, 2004

namespaces & assemblies


namespaces & assemblies









The import statement enables access to a namespace in an external library or within the current script. The syntax is very simple:


  import namespaceName;

where namespaceName
is the name of the required namespace. There is always the question as
to where the computer should search for the given namespace. A
namespace is a collection of classes that typically offer related
features or functions. An assembly, on the other hand, is a physical
file, deployed during installation of the .NET framework, or other
applications. File extensions
.dll or .exe are a clear indication of assemblies. Usually, your namespaces will be implemented in .dll files. What's the relationship between the .dll file name and the namespace name? Generally speaking, none. A single namespace can be distributed among several .dll files. Also, a single .dll file can include multiple namespaces. In practice, though, the name of the .dll is usually the name of the namespace, and the jsc.exe compiler does support this practice with the /autoref compilation switch.






Mitesh Mehta



Thursday, July 22, 2004

Data Structures in C#


Data Structures in C#










This six-part series that focuses on important data structures and their
use in application development. Also examines both built-in data structures
present in the .NET Framework, as well as essential data structures we'll have
to build ourselves.


Part 1: An Introduction
to Data Structures


Focuses on defining what data
structures are, how the efficiency of data structures is analyzed, and why this
analysis is important.


Part 2: The Queue,
Stack, and Hashtable


Examines three of the most
commonly studied data structures: the Queue, the Stack, and the
Hashtable.


Part 3: Binary Tress and
BSTs


Looks at a common data
structure that is not included in the .NET Framework Base Class Library:
binary trees.


Part 4: Building a
Better Binary Search Tree


Examination of AVL trees and
red-black trees, which are two different self-balancing, binary search tree data
structures, skip list data structure, an ingenious data structure that turns a
linked list into a data structure that offers the same running time as the more
complex self-balancing tree data structures


Part 5: From Trees to
Graphs


All about graphs, one of the
most versatile data structures.


Part 6: Efficiently
Representing Sets


Data structures for implementing general and disjoint sets. A set is an
unordered collection of unique items that can be enumerated and compared to
other sets in a variety of ways.



Regards,
Mitesh Mehta
Microsoft Certified Professional
miteshvmehta@gmail.com

Some Questions On .Net


Some Questions On .Net









7.How to get updated data if datasource changes after filling dataset from datasource?
First
of all, a dataset should be used only when the data is not expected to
change very often. To get data that has been changed in the datasource
itself, means simply re-querying the datasource and re-filling the
dataset.

Shared & Protected methods


Shared methods










You
can have as many shared (static, in C#) methods as you want. But the
constraint here is that these methods will not be available from the
class's instance objects. Also, with shared methods the benefits of
object "construction" are not available, since shared methods can only
be called on the class directly rather than on the instances. Also,
shared methods do not have access to the class's non-shared or
non-static member variables.




Protected
members are different from friend members...Consider any class "A".
Friend methods are those that belong to a different class but have
access to A's members. Protected members are those members that can be
accessed by a derived class's methods - this is different from private
members which can only be accessed by the methods of A.
Consider the class "A" mentioned above:
Member type Access level
Private Can be accessed only by methods of A
Protected Can be accessed by methods of A as well as methods of any class derived from A

For
friend members, first of all, only "Methods" or "Functions" can act as
"Friends" of a class and a method belonging class B must be declared as
a friend method in class A so that B.FriendMethod() can access member
variables of class A.

Saturday, July 17, 2004

Presentations from TechED (US)


Presentations from TechED (US)










View or download the .NET Framework-related presentations
from TechEd 2004 (US)
using below link


http://msdn.microsoft.com/netframework/support/training/teched2004/



The following some of presentations that I liked,


1) Exploring What's New in the CLR 2.0
2) Visual C# Best Practices
3)
Visual C# 2005: Language Enhancements
4) Visual Studio: Deploying NET
Applications with Ease
5) .NET and J2EE Strategies for Interoperability


There are more inside.. worth a reference, download ASAP!!



Regards,
Mitesh Mehta
Microsoft Certified Professional
miteshvmehta@gmail.com


Beta 1 .NET FrameWork 2.0 available for Public Download


Beta 1 .NET FrameWork 2.0 available for Public Download










The Beta 1 .NET Framework 2.0 SDK and redistributables are available for
download.


You can find them here:




Regards,
Mitesh V. Mehta
Microsoft Certified Professional

miteshvmehta@gmail.com

New ADO.NET 2.0


New ADO.NET 2.0










With the new release of
Visual Studio .NET 2005 Beta 1 and the .NET Framework 2.0 Beta Microsoft has
included a lot of nice enhancements to ADO.NET 2.0. By either using the DAAB or
writing it your self, you could get generic provider factories. Microsoft has
now included this in ADO.NET 2.0 along with a lot of other nice enhancements.
For those using SQL Server and wanting to provide a list of servers to your
users, we would have to PInvoke SQL DMO. Now there is a new base class called
DbEnumerator. The SqlClient support for this class will return a list of SQL
servers. There is a ton of features that you can read more about at the
following link...

http://msdn.microsoft.com/data/default.aspx?pull=/library/en-us/dnvs05/html/ado2featurematrix.asp



Regards,
Mitesh Mehta
Microsoft
Certified Professional


Refactoring in Whidbey


Refactoring in Whidbey









Code refactoring means restructuring your code so that the original
intention of the code is preserved.

Example of code refactoring is extracting a block of code and placing it
into a function for more efficient code reuse. In Visual Studio .NET 2005
(codenamed Whidbey), a code refactoring engine is built in.


Read more here..



MSDN has also posted a good article on Refactoring for C# Code Using
Visual Studio 2005 that introduces the concept of refactoring and covers many of
the techniques that are supported in the new IDE.




Regards,
Mitesh Mehta
Microsoft Certified Professional
miteshvmehta@gmail.com


Friday, July 16, 2004

Boxing and Unboxing


Boxing and Unboxing









It's
better to say that boxing (and unboxing) is a specialised form of
casting or type-casting. In .NET, every class derives from the "object"
class. Since the "object" class is the base class of all objects, any
object can be cast to the type "object" and then reconverted to the
specific type. The conversion from specific type to "object" is called
boxing and the reverse is called unboxing. Unlike traditional casting,
any object or datatype can be boxed and unboxed. In traditional
casting, there are certain limitations. For example, string type cannot
be cast into, say, int type. But any object or variable can
be cast to "object". So in simple terms, boxing is casting from
specialised type to type "object" and unboxing is the reverse.

Regards,
Mitesh Mehta
Microsoft Certified Professional

miteshvmehta@gmail.com


Monday, July 12, 2004

Add/Remove Programs feature in Control Panel







To utilize the Add/Remove Programs feature in Control Panel, you must add a
key to the Registry under

HKEY_LOCAL_MACHINES\Software\Microsoft\Windows\CurrentVersion\Uninstall\Uniq
ueName

where UniqueName will be any Unique name that you can use for your program
identification


Note: Goto Start->Run - Type "Regedit" and browse to the location to see for
yourself...

Mitesh Mehta
M.C.P. (.Net)

Some Questions On .Net


Some Questions On .Net









1.How many classes can a single dll can have?
A single DLL (.net assembly) can have many classes / a single class.
2.how to create permenant cookie?
In Classic Asp, we used to set the "Expires" property to "Never" to the cookie object, I'm sure microsoft has kept it that way!.
3.what is difference between response.write() and response.output.write()?
Response.Output.Write() -- writes the output in the format specified, where as Response.Write() does not.
4.how to kill a session explicitly?
you mean programatically?,
Session.Abandon()
5.how to make a wrap up call to web service?
What
do you mean by wrap up call, webservice exposes some methods over the
web- that's why it is called web method, once added web-reference to a
webservice to a dotnet web/windows application, a proxy is created for
you(client) and you can make webmethod call , as if the object is
available locally.
If we're talking about non-.net
client(like Java), then soap / xml is used to post the request to the
.Net Web method(s). in order to execute them and get values .
6.what os bubbled event?
Pass!.
7.How to get updated data if datasource changes after filling dataset from datasource?
take care,


New features in .NET Framework 2.0


New features in .NET Framework 2.0











The .NET Framework 2.0 introduces enhancements across the .NET Framework.
Windows client application development will be simplified through new controls
and designer features, while the introduction of "ClickOnce" technology will
dramatically ease Windows client application deployment. ASP.NET 2.0 introduces
a collection of new features that refine Web application development and
radically reduce coding effort. Other enhancements include more productive
ADO.NET data access, support for the latest Web services standards, and expanded
functionality for device-based development.


Common Language Runtime 2.0


Generics: Generics are classes and methods that work
uniformly on values of different types and can greatly improve developer
productivity by boosting code reuse.


Edit and Continue: The feature that made Visual Basic
“RAD” is now in the core CLR, enabling developers to halt program execution,
change a line of code, and continue running it without a full
recompilation.


Performance and Load Time: The CLR now loads more quickly
and takes up less memory footprint.


Windows Forms 2.0


Application Deployment: Windows Forms 2.0 introduces
“ClickOnce,” which makes it simple for developers to package and deploy
applications and simplifies the inclusion of pre-requisites in the installation
package. ClickOnce further provides a simple way for administrators and users to
deploy and update applications.


Visually Stunning Presentation: Windows Forms 2.0 brings
together the capability to build applications that look like Microsoft Office
and increases flexibility and control over how you can position controls on the
forms. It includes a new grid control, a Sound Player control, a Web Browser
control and an Active Document Host control. Beyond that, in order to make your
application look more like Microsoft Windows or Office, we have made Windows
Forms controls render with visual styles by default, and we have created a new
menu, toolbar, and status bar family of controls called ToolStrips.


ASP.NET 2.0


Productivity and Customizability: ASP.NET 2.0 includes
support for membership (user name/password credential storage) and role
management services. The personalization service enables quick storage/retrieval
of user settings and preferences, facilitating rich customization with minimal
code. Master Pages now enable flexible page UI inheritance across sites.
Augmenting all these infrastructure features are more than 45 new server
controls in ASP.NET 2.0 that enable powerful declarative support for data
access, login security, wizard navigation, image generation, menus, treeviews,
portals, and more.


UI Adaptability: All standard ASP.NET 2.0 controls are
now built with a rich UI adapter extensibility architecture that enables
customization of output for different browsers and devices. All built-in ASP.NET
controls with the <asp:> prefix are now mobile enabled in Whidbey, which
allows developers to automatically target more than 300+ unique devices that
support a variety of different markup standards (WAP/WML, XHTML Mobile, cHTML,
etc).


Administration and Management: ASP.NET 2.0 includes
configuration management APIs, enabling developers to create, read, and update
Web.config and machine.config configuration files and an admin tool that plugs
into the existing IIS Administration MMC, enabling an administrator to
graphically read or change any setting within our XML configuration files. It
also includes a new application deployment utility that will enable both
developers and administrators to precompile a dynamic ASP.NET application prior
to deployment protecting your source code. Finally, ASP.NET 2.0 provides
health-monitoring and tracing support to enable administrators to be
automatically notified when an application on a server starts to experience
problems.


Speed and Performance: ASP.NET 2.0 is 64-bit enabled so it
can take advantage of the full memory address space of new 64-bit processors and
servers. ASP.NET 2.0 also includes automatic database server cache invalidation
enabling developers to cache database-driven pages and partial page content and
have ASP.NET automatically invalidate these cache entries and refresh the
content whenever the back-end database changes.


Regards,
Varad
Microsoft Solutions Group



.NET Framework 1.0 SP3 and 1.1 SP1 Tech Preview Available for Public Download


.NET Framework 1.0 SP3 and 1.1 SP1 Tech Preview Available for Public Download










.NET Framework 1.0 SP3 and 1.1 SP1 Tech Preview Available for Public Download




Microsoft had made technology
preview versions of the .NET Framework 1.0 SP3 and .NET Framework 1.1 SP1
available for developers to download so they can test their .NET
Framework-based applications with these service packs applied. Though these are
unsupported technology previews, we would like to ask your help in ensuring the
quality of the service packs by downloading them, testing your existing
applications on them, and giving us feedback.




These two service packs
address issues with the .NET Framework 1.0 and 1.1 including:



<![if !supportLists]>·
<![endif]>All
customer issues addressed with hotfixes



<![if !supportLists]>·
<![endif]>Improved
importing of WSDL



<![if !supportLists]>·
<![endif]>Data
Execution prevention<o:p></o:p>



<![if !supportLists]>·
<![endif]>Buffer
overrun protection




Customers can
download
the technology previews from <st1:place
w:st="on"><st1:PlaceName
w:st="on">Microsoft.com</st1:PlaceName> <st1:PlaceName
w:st="on">Download</st1:PlaceName> <st1:PlaceType
w:st="on">Center</st1:PlaceType></st1:place>
at: <o:p></o:p>




.NET
Framework 1.0 Service Pack 3 Tech Preview:
http://www.microsoft.com/downloads/details.aspx?FamilyId=CF52CA95-F2CC-459F-87EE-C17D16E22F08&displaylang=en



.NET
Framework 1.1 Service Pack 1 Tech Preview:
http://www.microsoft.com/downloads/details.aspx?FamilyId=12721880-CB9F-4481-9610-987DE96532E7&displaylang=en



.NET
Framework 1.1 Service Pack 1 Tech Preview for Windows Server 2003:
http://www.microsoft.com/downloads/details.aspx?FamilyId=DA1C20AD-35AE-4CEA-8451-730FCD603383&displaylang=en




If you have feedback,
please send it to us at http://communities.microsoft.com/newsgroups/default.asp?icp=techpreview&slcid=us;




Thanks very much for your
time,






MS Press - Ebook of 70-310/70-320


MS Press - Ebook of 70-310/70-320











HelpProvider Class









HelpProvider Class

HelpProvider Class in Windows form has a method SetHelpString()...
This method will associate a string that you provide with the control
specified... This help will be shown when the user presses F1 while the
control has focus...

Example

Private objhelpProvider As System.Windows.Forms.HelpProvider
Me.objhelpProvider.SetHelpString(Me.txtZipCode, "Just enter the first 5
digits for Zip code, this applies to US only...")
Me.objhelpProvider.SetShowHelp(Me.txtZipCode, True)

Mitesh Mehta

Application Domains Basics









Application Domains Basics

Inter process communication is always painful... The memory pointers in one
process many a times do not make a lot of sense in the other process... To
tackle this problem and many others; Application Domains are introduced in
.Net... There can be more than one Application Domain running under the same
process... Application Domain provides nearly equivalent level of isolation
as would a separate process and at the same time saves the hits of
cross-process communications... By having high isolation you can prevent
failure of one application to affect other application...

Note: There is lot more to application domains and its a very interesting
topic, do give it some time of yours it will be worthwhile..

Mitesh Mehta


Tuesday, June 29, 2004

Understanding data providers,data drivers, Odbc,oledb etc









ODBC
- Short for Open DataBase Connectivity, a standard database access
method developed by Microsoft Corporation. The goal of ODBC is to make
it possible to access any data from any application, regardless of
which database management system (DBMS) is handling the data. ODBC
manages this by inserting a middle layer, called a database driver ,
between an application and the DBMS. The purpose of this layer is to
translate the application's data queries into commands that the DBMS
understands. For this to work, both the application and the DBMS must
be ODBC-compliant -- that is, the application must be capable of
issuing ODBC commands and the DBMS must be capable of responding to
them. Since version 2.0, the standard supports SAG SQL.

OLE DB
Over
the years, ODBC has become the standard for client/server database
access. ODBC provides a standards-based interface that requires SQL
processing capabilities and is optimized for a SQL-based approach.
However, what happens if you want to access data in a nonrelational
data source that doesn't use SQL (e.g., Microsoft Exchange Server,
which doesn't store data relationally)?
Enter OLE DB. OLE DB
builds on ODBC and extends the technology to a component architecture
that delivers higher-level data-access interfaces. This architecture
provides consistent access to SQL, non-SQL, and unstructured data
sources across the enterprise and the Internet. (In fact, for access to
SQL-based data, OLE DB still uses ODBC because it's the most optimized
architecture for working with SQL.) OLE DB consists of three
components: the data consumer (e.g., an application); the data
provider, which contains and exposes data; and the service component,
which processes and transports data (e.g., query processors, cursor
engines). OLE DB is one API that operates against SQL data sources and
non-SQL data sources such as mail and directories

.Net Data Providers
ADO.NET
Data Providers are again, a new version of universal data access, that
access data sources directly to gain performance advantages. ADO.Net
also makes good use of XML standards to more effeciently transmit and
cache data. It uses a more TCP-like connectionless metaphor so that
all ADO.Net providers use sessionless connections. They get data and
don't maintain a session on the server. NET data providers. An
essential component of ADO.NET, a .NET data provider implements
ADO.NET's interfaces. For example, a .NET data provider would implement
the DataReader object so that either your application or the DataSet
object could use it.

Interface vs. Abstract classes







Interface vs. Abstract
classes

Abstract class needs to have at least one "pure
virtual method" *
In case of Interface all the methods should
be "pure virtual"

An Abstract class can have all methods as
"pure virtual" and still it will
not allow multiple
inheritance... With Interface multiple inheritance is
possible
in .Net...

Various access modifiers such as abstract,
protected, internal, public,
virtual, overrides etc are not
useful in case of Interface but they are in
case of Abstract
classes

Class implementing Interface has to implement all
the methods of the
Interface, this is not required in case of
Abstract classes

As Interface cannot be instantiated, they
do not have constructors and
destructors like the way Abstract
classes can...

Interface cannot contain a static method
whereas an Abstract class can
have...

There are few
more points which I can recollect but I think that this
is
enough for a tip... If anyone needs more info do write back
to me... :-)


* pure virtual method is a method which
has just definition but
not
implementation...

****************************************************************************
****************************************************************************
*******************************************
An
addition to yesterday's tip... We cannot access static member of a
class
using object of a class in C#, though this is possible in
VB.Net... Thanks
to Jacob Cynamon, MS & Kathleen Dollard,
MVP for quickly reminding the
same... Thanks all for sending a
wonderful queries & feedbacks and making
my evenings more
useful...

****************************************************************************
****************************************************************************
*******************************************

PS:
Many of us work on weekends, I don't think (current thought!!)
that its
a good practice doing that, at least if you are being
gauged on the basis of
your willingness to work on weekends
then its surely very bad... I am trying
to start a movement to
abolish this social evil of working on weekends, so
no tips on
weekends...:-)
BONUS TIP: Spend time with your family this
weekend... :-)


Wednesday, June 09, 2004

How can I run another application or batch file from my Visual C# .NET code?



[Author: Mitesh Mehta]


Suppose you want to run a command line application, open up another Windows program, or even bring up the default web browser or email program... how can you do this from your C# code?


The answer for all of these examples is the same, you can use the classes and methods in System.Diagnostics.Process to accomplish these tasks and more.


Example 1. Running a command line application, without concern for the results:

private void simpleRun_Click(object sender, System.EventArgs e){
 System.Diagnostics.Process.Start(@"C:\listfiles.bat");
}

Example 2. Retrieving the results and waiting until the process stops (running the process synchronously):

private void runSyncAndGetResults_Click(object sender, System.EventArgs e){
 System.Diagnostics.ProcessStartInfo psi =
  
new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat");
 psi.RedirectStandardOutput =
true;
 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
 psi.UseShellExecute =
false;
 System.Diagnostics.Process listFiles;
 listFiles = System.Diagnostics.Process.Start(psi);
 System.IO.StreamReader myOutput = listFiles.StandardOutput;
 listFiles.WaitForExit(2000);
 
if (listFiles.HasExited)
 {
  
string output = myOutput.ReadToEnd();
  
this.processResults.Text = output;
 }
}

 Example 3. Displaying a URL using the default browser on the user's machine:

private void launchURL_Click(object sender, System.EventArgs e){
 
string targetURL = @Mitesh Mehta ;
 System.Diagnostics.Process.Start(targetURL);
}

In my opinion, you are much better off following the third example for URLs, as opposed to executing IE with the URL as an argument. The code shown for Example 3 will launch the user's default browser, which may or may not be IE; you are more likely to provide the user with the experience they want and you will be taking advantage of the browser that is most likely to have up-to-date connection information.