Create database connection
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace DalLibrary
{
class DBConn
{
private static SqlConnection conn;
private DBConn()
{
}
/// <summary>
/// get database connection
/// </summary>
/// <returns></returns>
public static SqlConnection GetDbConnection()
{
try
{
if (conn == null)
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["PhoneConString"].ToString());
conn.Open();
}
else if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
}
catch (Exception)
{
throw;
}
return conn;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace DalLibrary
{
class DBConn
{
private static SqlConnection conn;
private DBConn()
{
}
/// <summary>
/// get database connection
/// </summary>
/// <returns></returns>
public static SqlConnection GetDbConnection()
{
try
{
if (conn == null)
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["PhoneConString"].ToString());
conn.Open();
}
else if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
}
catch (Exception)
{
throw;
}
return conn;
}
}
}
0 comments:
Post a Comment