/// <summary> /// Creates an instance of a ConnectionHolder object. /// </summary> /// <param name="connection">This is the actual connection object assigned.</param> /// <param name="parent">The object that will be attached to this connection. For example, the data object that is requesting it.</param> public ConnectionHolder(OdbcConnection connection, object parent) { _thisConnection = connection; _thisAlias = new ConnectionAlias(); _parent = parent; _persistent = false; }
public ConnectionHolder(OdbcConnection connection, object parent, ConnectionAlias alias) { _thisConnection = connection; _thisAlias = alias; _parent = parent; _persistent = false; }
public void RemoveConnection(ConnectionAlias alias) { for (int i = 0; i < ConnectionPool.Count; i++) { if (alias.CompareToConnection(ConnectionPool[i].Connection)) { ConnectionPool.RemoveAt(i); break; } } }
public OleDbConnection AddConnection(ConnectionAlias alias) { OleDbConnection newConnection; newConnection = new OleDbConnection(alias.GetConnectionString()); try { newConnection.Open(); } catch (Exception err) { throw new Exception("The connection test for the newly added connection failed.", err); } return(newConnection); }
public void DefaultInitialization(string Table) { if (_dataSet == null) { _dataSet = new DataSet("DentalClaim"); } if (_dataSet.Tables[Table] == null) { _dataTable = new DataTable(Table); _dataSet.Tables.Add(_dataTable); } else { _dataTable = _dataSet.Tables[Table]; } _primaryKeyFields = new PrimaryFieldsCollection(); if (_connectionAlias == null) { _connectionAlias = new ConnectionAlias(); } if (_connectionHandler == null) { _connectionHandler = new ConnectionHandler(); _connectionHandler.AddConnection(_connectionAlias); // Persistent Connection } if (_reservedKeys == null) { _reservedKeys = new ReservedKeyCollection(); } _dbcmdData = new OleDbCommand(); _dbadpData = new OleDbDataAdapter(_dbcmdData); _searchSQL = ""; _dataSearchType = SearchTypes.Exact; _dataRow = _dataTable.NewRow(); }
public OdbcConnection RequestConnection(ConnectionAlias alias, object obj) { return(AddConnection(alias).Connection); // Check connections /* * for (int i = 0; i < ConnectionPool.Count; i++) * { * try * { * if (alias.CompareToConnection(ConnectionPool[i].Connection)) * { * * if (ConnectionPool[i].Status != ConnectionHolderStatus.Active) * { * ConnectionHolder ch = ConnectionPool[i]; * ch.ParentObject = obj; * * if (ch.Status == ConnectionHolderStatus.Closed) * ch.Connection.Open(); * * return ch.Connection; * } * } * } * * catch (Exception err) * { * // Log if not an invalid index, connection pool was modified during search...ignore and allow it to get a new connection * if (i <= ConnectionPool.Count) * { * LoggingHelper.Log("Error requesting connection in ConnectionHandler.RequestConnection. i = " + i + " Count = " + ConnectionPool.Count, LogSeverity.Error, err, false); * } * break; * } * } */ // Connection could not be found, add it // return RequestConnection(alias, obj); }
public void AddConnection(ConnectionAlias alias, bool persistent) { OdbcConnection newConnection; for (int i = 0; i < ConnectionPool.Count; i++) { if (alias.CompareToConnection(ConnectionPool[i].Connection)) { // This connection already exists if (ConnectionPool[i].Status == ConnectionHolderStatus.Active) { // This connection is currently in use by another object // So create an identical connection instead } } } newConnection = new OdbcConnection(alias.GetConnectionString()); try { newConnection.Open(); if (!persistent) { newConnection.Close(); } } catch (Exception err) { LoggingHelper.Log("Error in ConnectionHandler.AddConnection", LogSeverity.Error, err, false); throw new Exception("The connection test for the newly added connection failed.", err); } // Connection test succeeded ConnectionHolder newConnHold = new ConnectionHolder(newConnection, null); newConnHold.PersistentConnection = persistent; ConnectionPool.Add(newConnHold); }
public bool CompareToConnection(ConnectionAlias conCompareAlias) { // Look for databasename if (conCompareAlias.DatabaseName != DatabaseName) { return(false); } // Look for servername if (conCompareAlias.ServerName != ServerName) { return(false); } // Look for username if (conCompareAlias.UserName != UserName) { return(false); } return(true); }
public ConnectionHolder AddConnection(ConnectionAlias alias) { OdbcConnection newConnection; /* * for (int i = 0;i < ConnectionPool.Count;i++) * { * if (alias.CompareToConnection(ConnectionPool[i].Connection)) * { * // This connection already exists * if (ConnectionPool[i].Status == ConnectionHolderStatus.Active) * { * // This connection is currently in use by another object * // So create an identical connection instead * } * } * } */ newConnection = new OdbcConnection(alias.GetConnectionString()); try { newConnection.Open(); } catch (Exception err) { LoggingHelper.Log("Error in ConnectionHandler.AddConnection", LogSeverity.Error, err, false); throw new Exception("The connection test for the newly added connection failed.", err); } // Connection test succeeded ConnectionHolder newConnHold = new ConnectionHolder(newConnection, null); ConnectionPool.Add(newConnHold); return(newConnHold); }
public OleDbConnection RequestConnection(ConnectionAlias alias, object obj) { return(AddConnection(alias)); }