Beispiel #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);
        }
Beispiel #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());
     }
 }