8.9.09

What is patindex and charindex in SQL

Patindex: Returns the string position of the first occurrence of pattern
Ex: Select patindex(‘%o%’, ‘Microsoft’)
Note: % is must
Charindex: Same as patindex but you can specify the string position.
Ex: charindex ( Expression1, Expression2 [ , start_location])

What is MSIL, IL

When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Microsoft intermediate language (MSIL) is a language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler. The common language runtime includes a JIT compiler for converting MSIL to native code.

Can I write IL programs directly

.assembly MyAssembly {}
.class MyApp {
.method static void Main() {
.entrypoint
ldstr "Hello, IL!"
call void System.Console::WriteLine(class System.Object)
ret
}
}
Just put this into a file called hello.il, and then run ilasm hello.il. An exe assembly will be generated.

What is Portable Executable (PE)

The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.

What is serialization in .NET?

Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes. Serialization/Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database).Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.

• Binary serialization preserves type fidelity, which is useful for preserving the state of an object between different invocations of an application. For example, you can share an object between different applications by serializing it to the clipboard. You can serialize an object to a stream, disk, memory, over the network, and so forth. Remoting uses serialization to pass objects "by value" from one computer or application domain to another.

• XML serialization serializes only public properties and fields and does not preserve type fidelity. This is useful when you want to provide or consume data without restricting the application that uses the data. Because XML is an open standard, it is an attractive choice for sharing data across the Web. SOAP is an open standard, which makes it an attractive choice.
There are two separate mechanisms provided by the .NET class library - XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are available for use in your own code.

6.9.09

Difference Between Product & Project in software

Project or Application:
* One client point of view if we are designing any software it is called project.
* This is custom made for a specific company in a specific domain, by taking the companies requirements.
ex: subiksha

Product :
* Global client point of view if we are designing any software it is called product.
ex: Ms-word.
* Many companies can use it irrespective of domain -
ex: Microsoft Office.

4.9.09

"Debugging" and "Tracing"

Tracing in .NET

So how has tracing been implemented in .NET? In .NET we have objects called Trace Listeners. A listener is an object that receives the trace output and outputs it somewhere; that somewhere could be a window in your development environment, a file on your hard drive, a Windows Event log, a SQL Server or Oracle database, or any other customized data store.

You can think of a Trace Listener as a conduit for passing tracing information from your application to the output store. We write tracing information on Trace Listeners and Trace Listeners in turn output the tracing information to the target media.

Storing tracing information in a data store of some sort provides the flexibility of analyzing the data later on and helps us find the error and performance related patterns in our applications.

The System.Diagnostics namespace provides the interfaces, classes, enumerations and structures that are used for tracing, debugging, and other application and system diagnostic services.

The System.Diagnostics namespace provides two classes named Trace and Debug that are used for writing errors and application execution information in logs. These classes are helpful during the development (to output debug messages, etc) and after deployment (to output performance related patterns, etc). These two classes are the same, except that the methods of the Trace class become part of the release build code whereas methods of the Debug class don't become part of the release build executable.

When you create a new project, define the DEBUG symbol to enable output with the Debug class and the TRACE symbol to enable output with the Trace class. If you create a project in Visual Studio .NET, its Debug version will have these symbols defined.



The System.Diagnostics namespace provides some Trace Listeners. The default Trace Listener is System.Diagnostics.DefaultTraceListener. Write and WriteLine methods of this class route the tracing information to the OutputDebugString and to the Log method of the attached debugger.

.NET framework also introduced the concept of Trace Switches. As the name implies, these are simply switches whose values can be controlled from outside of the application. What I meant by outside of the application is that once an application is compiled and converted to .exe or .DLL files, we don't have to change our code in order to change the values of these switches; we can just update the corresponding entries in .config files and the corresponding switches in our applications will have the updated values. To be more precise,

Trace Switches are simple objects that can be controlled externally through the .config files.

We will learn more about Trace Listeners and Trace Switches as we progress through the article. Following is a simple example of WriteLine method of the Trace and Debug classes.


Trace.WriteLine ("Hello 15Seconds Reader - Trace!") ;
Debug.WriteLine ("Hello 15Seconds Reader - Debug!") ;

When used in debug mode, both of these methods direct the tracing and debugging output to the output windows of the debugger; as shown in the following figure



NEED TO GET MORE ON "http://www.15seconds.com/Issue/020910.htm"

1.9.09

How to use Configuration file in DOTNET

app.config for Windows applications
Windows applications in VS.NET use the name app.config by default for the configuration file. This will not be automatically created when you create a Windows application. If you need a configuration file for your application, open your project in VS.NET, go to the 'Solution Explorer' and right click on the project name. Choose Add > Add new item from the menu and select 'Application Configuration file' from the list of choices. This will create an app.config file for you in the application root.

* To store values in the configuration file, you can create XML elements in the format:
?xml version="1.0" encoding= "utf-8" ?
configuration

appSettings
add key="DatabasePath" value="c:\\projects\data\spider.mdb"
add key="SupportEmail" value="webmaster-1@dotnetspider.com"
appSettings

configuration

* And to read from this config file, just use the following code in your application:

string dbPath =
System.Configuration.ConfigurationSettings.AppSettings["DatabasePath"];
string email =
System.Configuration.ConfigurationSettings.AppSettings["SupportEmail"];

ConfigurationSettings is the class used to access the contents of the configuration file. Since this class is part of the namespace System.Configuration, we have to use the fully qualified name System.Configuration.ConfigurationSettings. As a shortcut, you can use the using directive on top of the file like below:

using System.Configuration;

If you have the above directive on top of the file, then you can directly use the class ConfigurationSettings.

string dbPath = ConfigurationSettings.AppSettings["DatabasePath"];
string email = ConfigurationSettings.AppSettings["SupportEmail"];

In VB.NET, you have to use "( ... )" instead of the "[ ... ]"

Note: When you compile your application, VS.NET will automatically create a file called .exe.config in your bin\debug folder. The contents of the app.config will be automatically copied to this new config file when you compile the application. When you deliver the application to the end user, you have to deliver the exe and this new config file called .exe.config and NOT the app.config. Users can modify the data in .exe.config file and application will read the data from the config file, when restarted.

web.config for Windows applications

The web applications use the same concept, but they use a config file with the name web.config. There are couple of things to note in this case.

web.config is created automatically by VS.NET when you create any web project.
When you compile the web application, web.config is NOT renamed or copied to the BIN folder.
web.config has several default entries in it to support web/IIS configuration & security.
You can add the section in the web.config and add your key/value pairs in that section.
You can have separate web.config files for each directory in your web application, in addition to the one in the root. For each web page, by default, system will look for a web.config in the same folder as the page and if not found, then looks in the parent folder.