|
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
//using System.Configuration;
//using System.Web;
//using System.Web.Security;
//using System.Web.UI;
//using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
//using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for GetConnection
/// </summary>
public class GetConnection
{
#region Fields
private static GetConnection gconn;
//private static int numberOfConnections;
private static SqlConnection conn;
private static string defaultConnStr;
#endregion
public GetConnection()
{
//
// TODO: Add constructor logic here
//
defaultConnStr = ConfigurationManager.ConnectionStrings["ASAPConnectionString"].ToString();
if (null == defaultConnStr || defaultConnStr.Length == 0)
throw new Exception("The connection string was not found in GetConnection Class.");
else
conn = new SqlConnection(defaultConnStr);
}
#region Methods
public static GetConnection getInstance()
{
if (gconn == null) gconn = new GetConnection();
//numberOfConnections++;
return gconn;
}
public static SqlConnection getConnection()
{
if (conn == null)
{
InitDB();
}
return conn;
}
private static void InitDB()
{
if (null == defaultConnStr || defaultConnStr.Length == 0)
defaultConnStr = ConfigurationManager.ConnectionStrings["ASAPConnectionString"].ToString();
if (null == defaultConnStr || defaultConnStr.Length == 0)
throw new Exception("The connection string was not found in GetConnection Class.");
else
conn = new SqlConnection(defaultConnStr);
//conn = new SqlConnection("Data Source=HOSOXDEV;Initial Catalog=ASAP;Persist Security Info=True;User ID=asap;Password=asap");
//oconn.ConnectionString = "User Id=psa; Password=psa; Data Source=TST.RUSSELMETALS.COM;" +
//conn.ConnectionString = "User Id=psa; Password=psa; Data Source=PSA;" +
// "Min Pool Size=5; Connection Lifetime=180; Connection Timeout=60;" +
// "Incr Pool Size=2; Decr Pool Size=2";
//oconn.Open();
}
#endregion
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.