tags:

views:

56

answers:

3

Hi I want to make connection with sql server DB and maintain in singleton pattern. So is this functionality inbuilt in dot net ? or we mannually have to write the code for this scenario?

+1  A: 

Make use of sqlHelper class will do work for you which is related to database connections

Pranay Rana
So Is this sqlHelper manages the singleton internally ?
Lalit
@Lalit - sqlhelper contains all static methods so there is no need to bother about object creation it manage sqlconnection internally
Pranay Rana
+1  A: 

See here.

rursw1
+1  A: 

A lazy loaded singleton example

public sealed class Singleton

{ Singleton() { }

public static Singleton Instance
{
    get
    {
        return Nested.instance;
    }
}

class Nested
{
    // Explicit static constructor to tell C# compiler
    // not to mark type as beforefieldinit
    static Nested()
    {
    }

    internal static readonly Singleton instance = new Singleton();
}

}

nkr1pt