What is ODBC and OLEDB – Interview Question

Author posted by Jitendra on Posted on under category Categories c#, Microsoft, SQL Server and tagged as Tags , , with Leave a comment on What is ODBC and OLEDB – Interview Question

This articles explains in detail description of ODBC and OLEDB component of Microsoft and its Usage

Open Database Connectivity (ODBC) :

How ODBC Works
How ODBC Works

In computing, Open Database Connectivity (ODBC) provides a standard software interface for accessing database management systems (DBMS). The designers of ODBC aimed to make it independent of programming languages, database systems, and operating systems. Thus, any application can use ODBC to query data from a database, regardless of the platform it is on or DBMS it uses.

Continue reading “What is ODBC and OLEDB – Interview Question”

Difference in ADO and ADO.Net – Interview Question

Author posted by Jitendra on Posted on under category Categories c#, SQL Server and tagged as Tags , with 1 Comment on Difference in ADO and ADO.Net – Interview Question

Basic comparison between ADO and ADO.Net component in .Net Framework

Following are the basic difference between the ADO and ADO.Net in Microsoft .Net framework.

ADO.Net
ADO.Net

Continue reading “Difference in ADO and ADO.Net – Interview Question”

What is managed and unmanaged code

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags , with Leave a comment on What is managed and unmanaged code

What is managed and unmanaged code in .Net technology.

Visual Studio have made the life of developer very easy by providing the powerful interfaced IDE which helps to create the applications faster than any other technology. We all remember the coding in Turbo C compiler in which the output produced is “machine level language“.

Before Visual studio 2003, the output produced by the compilers were machine level language which can be pronounced as “UnManaged code“. Machine level language compiles and run on same machine or machine having same chip or configuration but it is not sure that it will run on another machine.

After Visual studio 2003, the output produced by the compilers of C# and VB were not “machine level language”, instead it was “Intermediate Language” with some metadata info which is executed by the “Common Language Runtime (CLR)“. so we can say that output produced by the compilers of C# and VB after Visual studio 2003 is “Managed Code“.

To read more on this topic, please refer below good articles:

  1. What is Managed Code ?
  2. Managed, Unmanaged, Native.

Logging made easy in .NET – log 4 net

Author posted by Jitendra on Posted on under category Categories c#, Microsoft and tagged as Tags , with 1 Comment on Logging made easy in .NET – log 4 net

How to use the log 4 net in .Net application. Example, demonstration and sourcecode

Logging is the part of development which is normally not included in Product / Software release but at the same time it is necessary to create the logging mechanism in your software module.

implement log4net in .net

Continue reading “Logging made easy in .NET – log 4 net”

How to read value from Configuration file – ( app.config or web.config )

How to read value from Configuration file – app.config or web.config in C# application or web application

One of the best practice used in .NET application is to store the constants like Database connection in app.config in case of dll or standalone application or web.config in case of websites.

To achieve this, we have to follow below steps:

add reference of System.Configuration in .NET
add reference of System.Configuration in .NET

Lets consider below code in web.config

Continue reading “How to read value from Configuration file – ( app.config or web.config )”

Static class

Author posted by Jitendra on Posted on under category Categories c# with Leave a comment on Static class

Example of Static Class, its usage and benefits

C# introduced a new feature known as Static Class.

A class which has only Static Methods is known as Static Class.

Benefit of Static Class:

  • Object of static class cannot be created.
  • All methods and members can be accessed by class Name.

Note :

  • All methods of static class must be specified explicitly by keyword static.
  • Static class cannot have instance constructor but it can have Static Constructor.

Example:


using System;
static class Shape
 {
    public static double GetArea(double Width, double height)
    {
        return Width * Height;
    }
 }

class Ractangle
{
   private void GetRactangleArea()
   {
     Double Area;
     Area = Shape.GetArea(10, 5);
   }
 }

Explanation:

In above Example Shape is Static class and contains static method named GetArea().

And other class (Rectangle) access the GetArea() method without creating the instance of class Shape.

Get Week of the Year

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags with Leave a comment on Get Week of the Year

get the Week Number of the year in C#

        /// <summary>
        /// Gets the week number of Year.
        /// </summary>
        /// <param name="dtPassed">The dt passed.</param>
        /// <returns></returns>
        private int GetWeekNumber(DateTime dtPassed)
        {
            CultureInfo ciCurr = CultureInfo.CurrentCulture;
            int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
            return weekNum;
        }

Log Event in Windows Operating System Using C#

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags with Leave a comment on Log Event in Windows Operating System Using C#

Tutorial on Logging Message in EventLog of Microsoft Windows.

Below is the Utility function used to log the message in Microsoft Windows Operating Systems.

class Program
    {
        static void Main(string[] args)
        {
            LogMessage("ShivaSoftBlog - Error Message", EventLogEntryType.Error);
            LogMessage("ShivaSoftBlog - Failure Audit Message", EventLogEntryType.FailureAudit);
            LogMessage("ShivaSoftBlog - Information Message", EventLogEntryType.Information);
            LogMessage("ShivaSoftBlog - Success Audit Message", EventLogEntryType.SuccessAudit);
            LogMessage("ShivaSoftBlog - Warning Message", EventLogEntryType.Warning);
            Console.WriteLine("LOg Success");
            Console.Read();
        }

        private static void LogMessage(string message, EventLogEntryType logType)
        {
            if (!EventLog.SourceExists("ShivaSoftBlog"))
                EventLog.CreateEventSource("ShivaSoftBlog", "Application");

            EventLog ncsLog = new EventLog();
            ncsLog.Source = "ShivaSoftBlog";
            ncsLog.WriteEntry(message, logType);

        }
    }

Background and foreground thread in c#

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags with 1 Comment on Background and foreground thread in c#

Example of Threading in C#. Includes Foreground and Background Threading.

  • Foreground threads have the ability to prevent the current application from terminating. The CLR will not shut down an application (which is to say, unload the hosting AppDomain) until all foreground threads have ended.
  • Background threads (sometimes called daemon threads) are viewed by the CLR as expendable paths of execution that can be ignored at any point in time (even if they are currently laboring over some unit of work). Thus, if all foreground threads have terminated, any and all background threads are automatically killed when the application domain unloads.
  • It is important to note that foreground and background threads are not synonymous with primary and worker threads. By default, every thread you create via the Thread.Start() method is automatically a foreground thread. Again, this means that the AppDomain will not unload until all threads of execution have completed their units of work. In most cases, this is exactly the behavior you require.

    Example:

    Thread Foreground Background
    Threading in CSharp
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;
    namespace TestThread
    {
    class Program
    {
    static void Main(string[] args)
    {
    Program obj = new Program();
    obj.printInfo();
    //Create object of parameterized thread, so that you can pass parameter to any thread
    ParameterizedThreadStart pst = new ParameterizedThreadStart(obj.function1);
    //Bydefault threads are Foreground Thread
    Thread t1 = new Thread(pst);
    //Set Thread Name
    t1.Name = "Thread1";
    //Passs Parameter to thread
    t1.Start(true);
    //Create object of ThreadStart, it does not have any parameter
    ThreadStart ts = new ThreadStart(obj.function2);
    Thread t2 = new Thread(ts);
    t2.Name = "Thread2";
    //Make it Background Thread
    t2.IsBackground = true;
    //Run the thread
    t2.Start();
    Console.ReadKey();
    }
    public void function1(object val)
    {
    for (int i = 0; i < 5; i++)
    {
    Console.WriteLine("This is parameterized function1 by {0} and Value passed is {1} ", Thread.CurrentThread.Name, val);
    }
    }
    public void function2()
    {
    for (int i = 0; i < 5; i++)
    {
    Console.WriteLine("This is function2 by : " + Thread.CurrentThread.Name);
    }
    }
    public void printInfo()
    {
    System.Text.StringBuilder sb = new StringBuilder();
    sb.Append("*******************************************************n");
    sb.Append("            read Demo by ShivaSoft                     n");
    sb.Append("*******************************************************n");
    System.Console.WriteLine(sb);
    }
    }
    }