public void Dispose() { if (SQLConn != null) { if (SQLConn.State == ConnectionState.Open) { SQLConn.Close(); } SQLConn = null; } }
private object SQLQuery_ReturnScalar(string strSQL, bool generic) { try { MySqlConnection SQLConn; if (generic) { //Generic ConnectionString without Database MySqlConnectionStringBuilder specific_connString = new MySqlConnectionStringBuilder(Cognitivo.Properties.Settings.Default.MySQLconnString); MySqlConnectionStringBuilder generic_connString = new MySqlConnectionStringBuilder(); generic_connString.Server = specific_connString.Server; generic_connString.UserID = specific_connString.UserID; generic_connString.Password = specific_connString.Password; generic_connString.ConnectionTimeout = 1; SQLConn = new MySqlConnection(generic_connString.ToString()); } else { //Specific ConnectionString with Database SQLConn = new MySqlConnection(Cognitivo.Properties.Settings.Default.MySQLconnString); } MySqlCommand SQLCmd = new MySqlCommand(); object eSQL; SQLConn.Open(); SQLCmd = new MySqlCommand(strSQL, SQLConn); eSQL = (string)SQLCmd.ExecuteScalar(); SQLConn.Close(); return(eSQL); } catch { return(null); } }
public static async Task <Facility> FacilityByIdAsync(string id) { Facility data = null; try { DBFacType db = DBFactoryUtil.DBSettings(); DbConnection SQLConn; var iFactory = DBFactoryUtil.GetDbProviderFactoryFromConfigRow(); using (SQLConn = iFactory.CreateConnection()) { SQLConn.ConnectionString = db.ConnStr; using (DbCommand SQLCmd = SQLConn.CreateCommand()) { SQLConn.Open(); SQLCmd.CommandText = DBFactory.TransformSQL(SQL.GetFacilityById, db.DBType); DbParameter p; p = iFactory.CreateParameter(); p.DbType = DbType.String; p.Value = id; p.ParameterName = "1"; SQLCmd.Parameters.Add(p); //p = iFactory.CreateParameter(); //p.DbType = DbType.Int32; //p.Value = start; //p.ParameterName = "2"; //SQLCmd.Parameters.Add(p); using (DbDataReader i = SQLCmd.ExecuteReader()) { if (i.HasRows) { while (i.Read()) { data = new Facility { FacilityId = i["facilityid"].ToString(), FacilityName = i["facilityname"].ToString(), Address = i["address"].ToString(), Status = i["status"].ToString(), FacilityEia = i["eia"].ToString(), Remarks = i["remarks"].ToString(), SectorId = i["sectorid"].ToString(), SectorName = i["sectorname"].ToString(), ZoneId = i["zoneid"].ToString(), ZoneName = i["zonename"].ToString(), StateId = i["stateid"].ToString(), StateName = i["statename"].ToString(), LgaId = i["lgaid"].ToString(), LgaName = i["lganame"].ToString(), EntryDate = Convert.ToDateTime(i["entrydate"]), SamplePointCount = Convert.ToInt32(i["spcount"]), //Coordinates = Newtonsoft.Json.JsonConvert.DeserializeObject<Coordinates>(i["coordinates"].ToString()), //SamplePoints = GetSamplePointsByFacilityId(i["facilityid"].ToString()), //FacilityPersonel = GetFacilityPersonel(i["facilityid"].ToString()), //FacilityConsultant = GetFaciltyOperator(i["facilityid"].ToString()), //FacilityProduct = GetFacilityProductByFacilityId(i["facilityid"].ToString()), //FacilityRawMaterial = GetFacilityRawMaterialByFacilityId(i["facilityid"].ToString()), //FacilityWaste = GetFacilityWasteByFacilityId(i["facilityid"].ToString()), //EiaCert = i["eiacert"].ToString(), }; } } } SQLConn.Close(); } } } catch (Exception ex) { throw ex; } return(data); }