Translate

Friday, December 20, 2013

Abstract Class

An abstract class is a class which cannot be instantiated, which means you cannot create an object of an abstract class, it can only act as a base class and other classes can derive from it. 

Wednesday, January 30, 2013

Types of SQL Keys


We have following types of keys in SQL which are used to fetch records from tables and to make relationship among tables or views.
  1. Super Key

    Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.Example : Primary key, Unique key, Alternate key are subset of Super Keys.
  2. Candidate Key

    A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.
    Example: In below diagram ID, RollNo and EnrollNo are Candidate Keys since all these three fields can be work as Primary Key.
  3. Primary Key

    Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.
  4. Alternate key

    A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.
    Example: In below diagram RollNo and EnrollNo becomes Alternate Keys when we define ID as Primary Key.
  5. Composite/Compound Key

    Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.
  6. Unique Key

    Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values. For more help refer the article Difference between primary key and unique key.
  7. Foreign Key

    Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. For more help refer the article Difference between primary key and foreign key.
    Example : We can have a DeptID column in the Employee table which is pointing to DeptID column in a department table where it a primary key.

Thursday, December 13, 2012

Convert word file to pdf in c#


//Change the path of the .docx file and filename to your file name.
        object paramSourceDocPath = Server.MapPath("IITJEEPaper-1Final.docx");
        object paramMissing = Type.Missing;

        ApplicationClass wordApplication = new ApplicationClass();
        Document wordDocument = null;

        //Change the path of the .pdf file and filename to your file name.
        string paramExportFilePath = Server.MapPath("IITJEEPaper-1Final.pdf");
        WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
        bool paramOpenAfterExport = false;
        WdExportOptimizeFor paramExportOptimizeFor =
            WdExportOptimizeFor.wdExportOptimizeForPrint;
        WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
        int paramStartPage = 0;
        int paramEndPage = 0;
        WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
        bool paramIncludeDocProps = true;
        bool paramKeepIRM = true;
        WdExportCreateBookmarks paramCreateBookmarks =
            WdExportCreateBookmarks.wdExportCreateWordBookmarks;
        bool paramDocStructureTags = true;
        bool paramBitmapMissingFonts = true;
        bool paramUseISO19005_1 = false;

        try
        {
            // Open the source document.
            wordDocument = wordApplication.Documents.Open(
                ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing);

            // Export it in the specified format.
            if (wordDocument != null)
                wordDocument.ExportAsFixedFormat(paramExportFilePath,
                    paramExportFormat, paramOpenAfterExport,
                    paramExportOptimizeFor, paramExportRange, paramStartPage,
                    paramEndPage, paramExportItem, paramIncludeDocProps,
                    paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                    paramBitmapMissingFonts, paramUseISO19005_1,
                    ref paramMissing);
        }
        catch (Exception ex)
        {
            // Respond to the error
            //System.Windows.Forms.MessageBox.Show(ex.Message);
            Response.Write(ex.Message);
        }
        finally
        {
            // Close and release the Document object.
            if (wordDocument != null)
            {
                wordDocument.Close(ref paramMissing, ref paramMissing,
                    ref paramMissing);
                wordDocument = null;
            }

            // Quit Word and release the ApplicationClass object.
            if (wordApplication != null)
            {
                wordApplication.Quit(ref paramMissing, ref paramMissing,
                    ref paramMissing);
                wordApplication = null;
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }

Thursday, October 4, 2012

Sync data between multiple database

Option one is to enable binary logs on each laptop and then replay these on the master database when reconnected. You can use 

mysqlbinlog logfile > mysql --host=masterdbserver 

This should be straightforward. It will apply all changes from the offline laptops to the master. 

Option two is to sync only changed and inserted records from the laptops to the master with MySQL Table Sync (http://sourceforge.net/projects/mysqltoolkit). Use the --onlydo option for this. 

Then you have to get the changes back from the central database to the laptops. If you are using MyISAM tables, rsync might be the best option; otherwise you can use MySQL Table Sync again.

Friday, September 14, 2012

Multiple Interface Inheritance with same method name


public interface ITest 
{
    void Test();
}

public interface ITest2 

{
    void Test();
}

public class Dual : ITest, ITest2
{
    void ITest.Test() 
   {
        Console.WriteLine("ITest.Test");
    }
    void ITest2.Test() 
   {
        Console.WriteLine("ITest2.Test");
    }
}

var dual = new Dual();
ITest test = dual;
test.Test();
ITest2 test2 = dual;
test2.Test();

Thursday, September 6, 2012

Advantage and disadvantage of self hosting?


Advantages of Self-Hosting:
  • Is easy to use : With only a few lines of code you have your service running.
  • Is flexible : You can easily control the lifetime of your services through the Open() and Close() methods ofServiceHost.
  • Is easy to debug : Debugging WCF services that are hosted in a self-hosted environment provides a familiar way of debugging, without having to attach to separate applications that activate your service.
  • Is easy to deploy : In general, deploying simple Windows applications is as easy as xcopy. You don’t need any complex deployment scenarios on server farms, and the like, to deploy a simple Windows application that serves as a WCF ServiceHost.
  • Supports all bindings and transports : Self-hosting doesn’t limit you to out-of-the-box bindings and transports whatsoever. On Windows XP and Windows Server 2003, IIS limits you to HTTP only.

Disadvantages of Self-Hosting:
  • Limited availability : The service is reachable only when the application is running.
  • Limited features : Self-hosted applications have limited support for high availability, easy manageability, robustness, recoverability, versioning, and deployment scenarios. These scenarios have become a standard in last few years. Such features are provided by the WAS (Windows Activation Service) which is a part of IIS7 (delivered with Vista and Win2008). This hosting mechanism allows you to host the service by using of protocols like MSMQ, HTTP and TCP. 

What is charindex?

Sql charindex is a sql server function that indicates the first position of a character or a character string within another character string. When a character or character string is found with sql charindex, the starting position is indicated with a non-zero positive integer value. If a character or character string is not found with charindex, a zero integer value is returned. charindex's starting position is 1, unlike other index search functions that would normally return 0 as the first position. 


CHARINDEX ( expression1 ,expression2 [ , start_location ] ) 


expression1
Is an expression that contains the sequence of characters to be found. expression1 is an expression of the character string data type category.
expression2
Is an expression, typically a column searched for the specified sequence. expression2 is of the character string data type category.
start_location
Is the character position to start searching for expression1 in expression2. If start_location is not specified, is a negative number, or is zero, the search starts at the beginning of expression2start_location can be of type bigint.

Tuesday, September 4, 2012

What are Dead letter queues?

The main use of queue is that you do not need the client and the server running at one time. Therefore, it is possible that a message will lie in queue for long time until the server or client picks it up. But there are scenarios where a message is of no use after a certain time. Therefore, these kinds of messages if not delivered within that time span it should not be sent to the user.

What are Volatile queues?

There are scenarios in the project when you want the message to deliver in proper time. The timely delivery of message is more important than losing message. In these scenarios, Volatile queues are used.
 

What is SOAP?


SOAP, Simple Object Access Protocol is a communication protocol, a way to structure data before transmitting it, is based on XML standard. It is developed to allow communication between applications of different platforms and programming languages via internet.
It can use range of protocols such as HTTP, FTP, SMTP, Post office protocal 3(POP3) to carry documents.
Http-Get, Http-Post works with name/value pair which means transferring complex object is not possible with these protocols, whereas SOAP serializes complex structure, such as ASP.NET DataSets, complex arrays, custom types and XML nodes before transmitting and thus allows exchange of complex objects between applications.