Posts

Showing posts from April, 2010

Exploring MySQL in the Microsoft .NET Environment

During the free time today, I was looking for some articles on MySQL with .net. I found an awesome article about this. Author has explained a it in very detail and simple manner. You can read the article here . Enjoy!!!

Encoding and Decoding Base64 strings in C#

Encode a string from Base64 public static string EncodeTo64(string toEncode) { byte[] toEncodeAsBytes = System.Text.Encoding.Unicode.GetBytes(toEncode); string returnValue = System.Convert.ToBase64String(toEncodeAsBytes); return returnValue; } Decode a Base64 encoded string public static string DecodeFrom64(string encodedData) { byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData); string returnValue = System.Text.Encoding.Unicode.GetString(encodedDataAsBytes); return returnValue; }

Implementing Singleton in C#

Context You are building an application in C#. You need a class that has only one instance, and you need to provide a global point of access to the instance. You want to be sure that your solution is efficient and that it takes advantage of the Microsoft .NET common language runtime features. You may also want to make sure that your solution is thread safe. Implementation Strategy Even though Singleton is a comparatively simple pattern, there are various tradeoffs and options, depending upon the implementation. The following is a series of implementation strategies with a discussion of their strengths and weaknesses. Singleton The following implementation of the Singleton design pattern follows the solution presented in Design Patterns: Elements of Reusable Object-Oriented Software but modifies it to take advantage of language features available in C#, such as properties: using System; public class Singleton { private static Singleton instance; private Singleton() {} public s...

Constructor in C#

Introduction Broadly speaking, a constructor is a method in the class which gets executed when its object is created. Usually, we put the initialization code in the constructor. Writing a constructor in the class is damn simple, have a look at the following sample: public class mySampleClass { public mySampleClass() { // This is the constructor method. } // rest of the class members goes here. } When the object of this class is instantiated, this constructor will be executed. Something like this: mySampleClass obj = new mySampleClass() // At this time the code in the constructor will // be executed Constructor Overloading C# supports overloading of constructors, that means, we can have constructors with different sets of parameters. So, our class can be like this: public class mySampleClass { public mySampleClass() { // This is the no parameter constructor method. // First Constructor } public mySampleClass(int Age) { ...

Using the FOR XML Clause to Return Query Results as XML

SQL Server lets you retrieve data as XML by supporting the FOR XML clause, which can be included as part of your query. You can use the FOR XML clause in the main (outer) query as well as in subqueries. The clause supports numerous options that let you define the format of the XML data. A good artical.... read here . Reference: http://www.simple-talk.com/sql/learn-sql-server/using-the-for-xml-clause-to-return-query-results-as-xml/

SQL Server Index Basics

Image
Overview: One of the most important routes to high performance in a SQL Server database is the index. Indexes speed up the querying process by providing swift access to rows in the data tables, similarly to the way a book’s index helps you find information quickly within that book. In this article, I provide an overview of SQL Server indexes and explain how they’re defined within a database and how they can make the querying process faster. Most of this information applies to indexes in both SQL Server 2005 and 2008; the basic structure has changed little from one version to the next. In fact, much of the information also applies to SQL Server 2000. This does not mean there haven’t been changes. New functionality has been added with each successive version; however, the underlying structures have remained relatively the same. So for the sake of brevity, I stick with 2005 and 2008 and point out where there are differences in those two versions. Index Structures Indexes are created on co...

Why stored procedures

Why Consider Stored Procedures? 1. The first time the stored procedure is run, it gets compiled. This produces an execution plan—essentially a record of the steps that Microsoft® SQL Server™ must take to get the results specified by the T-SQL in the stored procedure. The execution plan is then cached in memory for future use. This improves the performance of the stored procedure in that SQL Server does not need to analyze the code again to figure out what to do with it; it can simply refer to the cached plan. This cached plan is available until SQL Server is re-started, or until it is aged out of memory due to low usage. 2. Performance : The cached execution plan used to give stored procedures a performance advantage over queries. However, for the last couple of versions of SQL Server, execution plans are cached for all T-SQL batches, regardless of whether or not they are in a stored procedure. Therefore, performance based on this feature is no longer a selling point for stored procedu...