// Could just have a set of static helper methods rather than a singleton! public List <Customer> getCustomers() { List <Customer> customers = new List <Customer>(); DbConection con = DbFactory.instance(); if (con.OpenConnection()) { DbDataReader dr = con.Select("SELECT CUST_ID, cust_name, cust_address, cust_city FROM customers;"); //Read the data and store them in the list while (dr.Read()) { Customer customer = new Customer(); customer.ID = dr.GetInt32(0); customer.Name = dr.GetString(1); customer.Address = dr.GetString(2); customer.City = dr.GetString(3); // etc..... customers.Add(customer); } //close Data Reader dr.Close(); con.CloseConnection(); } return(customers); }
public IHttpActionResult GetAvailableHotels([FromBody] Request request) { response = new Response(); response.Data = null; try { if (request.Session > 0 && request.User > 0) { var result = DbConection.GetListHoteles(); if (result != null) { response.Data = result; } } if (response.Data != null) { response.CodeError = 200; response.Message = "OK"; } else { response.CodeError = 100; response.Message = "No se logro insertar el log"; response.Data = false; } } catch (Exception ex) { response.CodeError = 300; response.Message = "Unexpected Error" + ex.ToString(); response.Data = false; } return(Ok(response)); }
public static DbConection instance() { if (null == m_instance) { DbFactory factory = new DbFactory(); m_instance = factory.getConection(); } return(m_instance); }
private DbConection getConection() { DbConection connection = null; try { m_properties = getProperties(); string provider = m_properties["Provider"]; if (provider.Equals("MySQL")) { connection = new MySQLCon(m_properties); } else if (provider.Equals("Microsoft.ACE.OLEDB.16.0")) { connection = new OleDatabaseConnection(m_properties); } else if (provider.Equals("Microsoft.ACE.OLEDB.12.0")) { // See https://www.microsoft.com/en-us/download/details.aspx?id=54920 for Office 365 // https://docs.microsoft.com/en-us/office/troubleshoot/access/cannot-use-odbc-or-oledb connection = new OleDatabaseConnection(m_properties); } else { // should throw unsupport exception here throw new DBException("Not supported provider '" + provider + "'"); } } catch (FileNotFoundException e) { Debug.WriteLine("Error file not found" + e.Message); connection = null; throw e; } catch (Exception e) { Debug.WriteLine("Property file parsing exception thrown : " + e.Message); connection = null; throw e; } return(connection); }
static void Main(string[] args) { DatabaseConection d1 = DbConection.GetDbConection(); DatabaseConection d2 = DbConection.GetDbConection(); if (d1 == d2) { Console.WriteLine("zelfde aanleg"); } DatabaseConection database = DatabaseConection.GetDbConection(); for (int i = 0; i < 10; i++) { string server = database.Server; Console.WriteLine("vraag request aan: " + server); Console.ReadKey(); } }
private void btnTest_Click(object sender, EventArgs e) { btnTest.Enabled = false; BusinessMetaLayer ml = BusinessMetaLayer.instance(); m_customers = ml.getCustomers(); m_bs.DataSource = m_customers; m_bs.ResetBindings(false); // Fill data grid DbConection con = DbFactory.instance(); con.OpenConnection(); dataSet = con.getDataSet("Select * from customers"); DataTable table = dataSet.Tables[0]; //FillInTextFields(table, 1); //set up the data grid view this.dataGridView1.DataSource = table; }
private DbConection getConection() { DbConection connection = null; try { m_properties = getProperties(); string provider = m_properties["Provider"]; if (provider.Equals("Microsoft.ACE.OLEDB.12.0")) { connection = new OleDatabaseConnection(m_properties); } else if (provider.Equals("Microsoft.ACE.OLEDB.14.0")) { connection = new OleDatabaseConnection(m_properties); } else if (provider.Equals("Microsoft.ACE.OLEDB.16.0")) { connection = new OleDatabaseConnection(m_properties); } else { throw new DBException("Not supported provider '" + provider + "'"); } } catch (FileNotFoundException e) { Debug.WriteLine("Error file not found" + e.Message); connection = null; throw e; } catch (Exception e) { Debug.WriteLine("Property file parsing exception thrown : " + e.Message); connection = null; throw e; } return(connection); }
public IHttpActionResult CreateBooking([FromBody] Request request) { response = new Response(); int result = 0; try { using (var model = new HOSTING_MANAGEREntities()) { model.Configuration.ProxyCreationEnabled = false; if (request.Session > 0 && request.User > 0 && request.Data != null) { result = DbConection.InsertBooking(JsonConvert.DeserializeObject <RIDER>(request.Data.ToString())); } if (result == 0) { response.CodeError = 200; response.Message = "OK"; response.Data = result; } else { response.CodeError = 100; response.Message = "No se logro insertar el log"; response.Data = false; } } } catch (Exception ex) { response.CodeError = 300; response.Message = "Unexpected Error" + ex.ToString(); response.Data = false; } return(Ok(response)); }
public AplEnvioAtividade() { context = DbConection.getContext(); db = new GenericDALImpl <ARQUIVO>(); }
public PeopleController(DbConection context, IWebHostEnvironment env) { _context = context; this.env = env; }
public MovieActorsController(DbConection context) { _context = context; }
public GendersController(DbConection context) { _context = context; }