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
2010-09-02 09:49:23
So Is this sqlHelper manages the singleton internally ?
Lalit
2010-09-03 05:09:34
@Lalit - sqlhelper contains all static methods so there is no need to bother about object creation it manage sqlconnection internally
Pranay Rana
2010-09-03 05:46:02
+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
2010-09-02 09:52:15