private string DeterminarNombreTabla(string nombreEntidad) { StringBuilder sb = new StringBuilder(); string conString = WebConfigurationManager. ConnectionStrings[Utiles.CNS].ConnectionString; string query = string.Format("SELECT table_name FROM information_schema.TABLES where table_schema = {0}", Utiles.NombreBaseDatos()); try { List <string> listaTablas = new List <string>(); if (fileContents == null) { using (OdbcConnection con = new OdbcConnection(conString)) using (OdbcCommand cmd = new OdbcCommand(query, con)) { con.Open(); using (OdbcDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { listaTablas.Add(reader.GetString(0)); } } con.Close(); } CacheItemPolicy policy = new CacheItemPolicy(); policy.AbsoluteExpiration = tiempoCache; List <string> filePaths = new List <string>(); string cacheFilePath = AppDomain.CurrentDomain.BaseDirectory + nombreArchivo; filePaths.Add(cacheFilePath); policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); fileContents = listaTablas; cache.Set("fileContentsTablaSistema", fileContents, policy); } else { listaTablas = fileContents; } if (listaTablas != null && listaTablas.Count > 0) { int cantidad = 0; foreach (string s in listaTablas) { //descomponemos los elementos if (nombreEntidad.ToUpper() == s.Replace("_", "").ToUpper()) { cantidad++; } if (cantidad > 0) { sb.Append(s); break; } } } } catch (Exception ex) { Utiles.Log(ex); throw ex; } return(sb.ToString()); }
private List <CamposTabla> ListaCamposTabla(string nombreTabla) { List <CamposTabla> lista = new List <CamposTabla>(); StringBuilder sb = new StringBuilder(); string conString = WebConfigurationManager. ConnectionStrings[Utiles.CNS].ConnectionString; //if (fileContents == null) //{ try { using (OdbcConnection con = new OdbcConnection(conString)) using (OdbcCommand cmd = new OdbcCommand("SELECT distinct column_name, ordinal_position, data_type, CHARACTER_MAXIMUM_LENGTH FROM information_schema.COLUMNS where table_name ='" + nombreTabla + "'", con)) { con.Open(); using (OdbcDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { CamposTabla campo = new CamposTabla(); campo.NombreColumna = reader.GetString(0); campo.Ordinal = int.Parse(reader.GetString(1)); campo.TipoDato = reader.GetString(2); campo.LargoBD = reader.IsDBNull(3) ? 0 : reader.GetDecimal(3); if (!lista.Exists(p => p.NombreColumna == campo.NombreColumna)) { lista.Add(campo); } } } con.Close(); } //CacheItemPolicy policy = new CacheItemPolicy(); //policy.AbsoluteExpiration = tiempoCache; //List<string> filePaths = new List<string>(); //string cacheFilePath = AppDomain.CurrentDomain.BaseDirectory + nombreArchivo; //filePaths.Add(cacheFilePath); //policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); //fileContents = lista; //cache.Set("fileContentsCampos", fileContents, policy); } catch (Exception ex) { Utiles.Log(ex); throw ex; } //} //else //{ // lista = fileContents; //} return(lista); }