Hi there,I saw an article in the http://www.yoda.arachsys.com/csharp/singleton.html, called Implementing the Singleton Pattern in C #, I write a DEMO use 5th version, code as follows:
public sealed class Singleton
{
Singleton()
{
InitSessionFactory();
}
private void InitSessionFactory()
{
}
public static Singleton Instance
{
get
{
return Nested.instance;
}
}
class Nested
{
static Nested()
{
}
internal static readonly Singleton instance = new Singleton();
}
public ISession GetSession()
{
return sessionFactory.OpenSession();
}
private ISessionFactory sessionFactory;
}
Usually it works well, but I found a problem when Instance occurs an exception, such as network disconnection, the result is exception when reading Instance, however,when the network reconnected, read the Instance again, the result is still exception , How can I recovery Instance?
Significance of this problem was, when the network happen connection problems, I need close program then restart or no.
Thanks.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Thanks Jimmanuel.
if network disconnection at programming start, the programming exception is :
'Instance' threw an exception of type 'System.TypeInitializationException'
{"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}
then, network is connection, the exception still:
'Instance' threw an exception of type 'System.TypeInitializationException'
{"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}
if network disconnection at programming already running, the programming exception is:
A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - Remote host forced to close an existing connection。)
even network is reconnection.