I assume in true time, your connection will open with out any matter.
and
cn
is always return value.
If so this error occurs one of "DATABASE", "PASSWORD" or "SERVERNAME" throws and exception. you can check it and populate it by using three if blocks instead of one if block for all conditions. keep the debug point before the first if block and check the code..
if(HttpContext.Current.Session["DATABASE"] != null)
if(HttpContext.Current.Session["PASSWORD"] != null)
HttpContext.Current.Session["SERVERNAME"] != null
{
}
Hope this will help to find out the real exception...