| Linux hosting5.siteguarding.com 3.10.0-962.3.2.lve1.5.88.el7.x86_64 #1 SMP Fri Sep 26 14:06:42 UTC 2025 x86_64 Path : /home/devsafetybis/.trash/yuvatrip.com/App_Code/ |
| Current File : /home/devsafetybis/.trash/yuvatrip.com/App_Code/databaseconnection.cs |
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for DBUtility
/// </summary>
public class Databases
{
public string DatabaseName { get; set; }
public string ConnectionString { get; set; }
}
public static class DatabaseDetail
{
public static Databases localhost { get { return new Databases { DatabaseName = "ytdb_new", ConnectionString = "CS_YTDB" }; } }
public static Databases YuvatripDataBase { get { return new Databases { DatabaseName = "ytdb_new", ConnectionString = "CS_YuvatripDatabase" }; } }
public static Databases YuvatripDB { get { return new Databases { DatabaseName = "YuvatripDB", ConnectionString = "CS_YuvatripDB" }; } }
}
public class DatabaseConnection
{
SqlConnection SQLConnection = null;
public DatabaseConnection(Databases DB)
{
this.Connect(DB.ConnectionString);
}
public DatabaseConnection(string connectionString = "CS_YuvatripDatabase")
{
this.Connect(connectionString);
}
private void Connect(string connectionString)
{
try
{
this.SQLConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[connectionString].ToString());
this.SQLConnection.Open();
}
catch (Exception ex)
{
// YTException.LogWrite(ex);
}
}
private void Disconnect()
{
try
{
this.SQLConnection.Close();
this.SQLConnection = null;
}
catch (Exception ex)
{
// YTException.LogWrite(ex);
}
}
public DataTable QueryData(string queryString, CommandType commandType)
{
try
{
DataTable Table = new DataTable();
SqlCommand Command = new SqlCommand(queryString, this.SQLConnection);
Command.CommandType = commandType;
SqlDataAdapter Adapter = new SqlDataAdapter(Command);
Adapter.Fill(Table);
this.Disconnect();
return Table;
}
catch (Exception ex)
{
//YTException.LogWrite(ex);
this.Disconnect();
return null;
}
}
public DataTable QueryData(SqlCommand command, CommandType commandType)
{
SqlCommand Command = new SqlCommand();
Command = command;
Command.Connection = this.SQLConnection;
Command.CommandType = commandType;
DataTable Table = new DataTable();
SqlDataAdapter Adapter = new SqlDataAdapter(Command);
Adapter.Fill(Table);
this.Disconnect();
return Table;
}
public int ExeNonQuery(string QueryString, CommandType CmdType = CommandType.Text)
{
var RetData = 0;
try
{
DataTable Table = new DataTable();
SqlCommand Command = new SqlCommand(QueryString, this.SQLConnection);
Command.CommandType = CmdType;
RetData = Command.ExecuteNonQuery();
this.Disconnect();
return RetData;
}
catch (Exception ex)
{
//YTException.LogWrite(ex);
return RetData;
}
}
public string ExeNonQuery(SqlCommand command, CommandType commandType)
{
try
{
SqlCommand Command = new SqlCommand();
Command = command;
Command.Connection = this.SQLConnection;
Command.CommandType = CommandType.StoredProcedure;
Command.CommandTimeout = 600;
SqlParameter returnstring = new SqlParameter("@returnstring", SqlDbType.NVarChar, 8000000);
returnstring.Direction = ParameterDirection.Output;
Command.Parameters.Add(returnstring);
Command.ExecuteNonQuery();
this.Disconnect();
return Command.Parameters["@returnstring"].Value.ToString();
}
catch (Exception ex)
{
//YTException.LogWrite(ex);
return "";
}
}
public dynamic ExeScaleQuery(string queryString, CommandType commandType)
{
String QueryString = queryString;
CommandType CommandType = commandType;
DataTable Table = new DataTable();
SqlCommand Command = new SqlCommand(QueryString, this.SQLConnection);
Command.CommandType = CommandType;
var retData = Command.ExecuteScalar();
this.Disconnect();
return retData;
}
}