Exemplo n.º 1
0
        /// <summary>
        /// Returns a new connection object to communicate with the database.
        /// </summary>
        ///
        /// <returns>
        /// A new <see cref="IDbConnection"/> object.
        /// </returns>
        ///
        public override IDbConnection CreateConnection()
        {
            IDbConnection conn = TargetDbProvider.CreateConnection();

            var listener = ConnectionStateListener;

            if (listener != null)
            {
                var dbConnection = conn as DbConnection;
                if (dbConnection != null)
                {
                    dbConnection.StateChange += StateChangeEventHandler;
                }
                else if (!_isNonDbConnectionErrorGiven && _log.IsErrorEnabled)
                {
                    _log.Error(string.Format(
                                   "Unable to detected connection state change as the " +
                                   "connection object from {0} doesn't inherit from {1}. " +
                                   "{2} will not be called.",
                                   TargetDbProvider,
                                   typeof(DbConnection).FullName,
                                   listener));
                    _isNonDbConnectionErrorGiven = true;
                }
            }
            return(conn);
        }
Exemplo n.º 2
0
 protected virtual IDbConnection DoCreateConnection(string user, string pass)
 {
     AssertUtils.ArgumentNotNull(TargetDbProvider, "TargetDbProvider");
     if (StringUtils.HasLength(user))
     {
         IDbConnection conn = TargetDbProvider.CreateConnection();
         string        s    = ConnectionString + separator + user + separator + pass;
         conn.ConnectionString = s;
         return(conn);
     }
     else
     {
         return(TargetDbProvider.CreateConnection());
     }
 }
 /// <summary>
 /// Determines whether the provided exception is in fact related
 /// to database access.  This can be provider dependent in .NET 1.1 since
 /// there isn't a common base class for ADO.NET exceptions.
 /// </summary>
 /// <param name="e">The exception thrown when performing data access
 /// operations.</param>
 /// <returns>
 ///     <c>true</c> if is a valid data access exception for the specified
 /// exception; otherwise, <c>false</c>.
 /// </returns>
 public virtual bool IsDataAccessException(Exception e)
 {
     return(TargetDbProvider.IsDataAccessException(e));
 }
 /// <summary>
 /// Extracts the provider specific error code as a string.
 /// </summary>
 /// <param name="e">The data access exception.</param>
 /// <returns>The provider specific error code</returns>
 public virtual string ExtractError(Exception e)
 {
     return(TargetDbProvider.ExtractError(e));
 }