Exemplo n.º 1
0
        protected IDbConnection GetConnection(string connectionName, DbProviderFactory factory)
        {
            var connString = EnableMasterSlave ? ConnectionConfigureManager.GetConnectionString(connectionName, ReadOnly) : Configuration.GetConnectionString(connectionName);

            if (string.IsNullOrWhiteSpace(connString))
            {
                throw new ArgumentNullException(nameof(connString), "The config of " + connectionName + " cannot be null.");
            }
            var conn = factory.CreateConnection();

            if (conn == null)
            {
                throw new ArgumentNullException(nameof(IDbConnection), "Failed to create database connection.");
            }
            conn.ConnectionString = connString;
            conn.Open();
            return(DbMiniProfiler == null ? conn : DbMiniProfiler.CreateConnection(conn));
        }
Exemplo n.º 2
0
        private IDbConnection CreateConnection(string connectionName)
        {
            var connString = ConnectionStringProvider.GetConnectionString(connectionName, EnableMasterSlave, ReadOnly);

            if (string.IsNullOrWhiteSpace(connString))
            {
                throw new ArgumentNullException(nameof(connString), "The config of " + connectionName + " cannot be null.");
            }
            var conn = new TDbConnection();

            if (conn == null)
            {
                throw new ArgumentNullException(nameof(IDbConnection), "Failed to create database connection.");
            }
            conn.ConnectionString = connString;
            conn.Open();
            return(DbMiniProfiler == null ? conn : DbMiniProfiler.CreateConnection(conn));
        }